Variable Scope
We have the following code:
var name = 'John',
obj = {
name: 'Mary',
whoIam: function() {
var name = 'James';
console.log( this.name );
setTimeout( function () {
console.log( this.name );
}, 100 );
}
};
obj.whoIam();What does it prints?
"Mary"
undefined
"John"Why?
Last updated
Was this helpful?