190
rated 0 times
[
197]
[
7]
/ answers: 1 / hits: 20093
/ 7 Years ago, fri, april 21, 2017, 12:00:00
I write this simple program to update value of JS hoisting. But as per my understanding global x need to update, but It is not updating.
x = 5;
var w = function(){
x = 7
var x;
console.log(x);
x = 10;
console.log(x);
};
w();
console.log(x);
Output:
- 7
- 10
- 5
Could anyone explain in more details why it did not update global x ?
Javascript work on reference of values so when I write x = 7, it should be update the global x. But it din't!
So I just want to why x =7 doesn't work ?
Thanks!
More From » javascript