In following examle, how in world does first window.object
(console.log
first time) contain variable a
that too with value '10'? As, there is no global function wrapping so concept of 'hoisting' does not occur, even if it occurs - a
will be hoisted as value undefined
.
I can understand second window object has property a
as '10', but how can first window object before declaring and putting variable value as '10' still containing it. What is happening?
Note: 'StackOverflow' wraps the code in its own global function, so not running here.
console.log(this);
var a = 10;
console.log(this);
Outcome:
Note: This code runs in 'chrome'.