I try to run a code below in browser. I thought property window.a
and global a
is the same cell in memory. Could somebody please give me a link to an article which explains this behaviour.
// undefined
// if (window.a) {}
// Uncaught ReferenceError: a is not defined
// if (a) {}
They are the same:
a = 1;
a === window.a // true
Edit: Sorry, was a bit too quick there... I diddnt answer anything. This article explains the difference pretty well: https://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/
"A Reference is considered unresolvable if its base value is undefined"
window.a // base value is window, reference object is a
a // base value is a