This is making me angry:
If I don’t do this:
var a;
And then do this:
if(a){
// doing stuff
}
It spits out this error:
ReferenceError: a is not defined
So how can I check if a variable is defined!
Please don’t tell me to use typeof.
EDIT:
a is defined by a library sometimes. I want to check if the library defined it so if not I define it so I can still use it in my code!
If you want to ensure the
ais declared, and not causing any reference error problem. You may add a re-declaration statement.In this case, if a is defined, nothing changes, otherwise it’s undefined.
NOTICE: this only works when
ais in global scope, check out comments for more details.