Why is this:
if(x)
alert('Available');
gives: ReferenceError: x is not defined
while it works:
if(window.x)
alert('Available');
Does not speak:
var x = "";
is equivalent to:
x = "";
is equivalent to:
window.x = "";
if the function is out , since all the code is surrounded with(window)?
To make it clearer: I know the difference between global member variables, but I want to know why getting an undeclared variable gives ReferenceError like x;, but window.xgives undefined? Shouldn't they give undefined?
source
share