In order to protect my code from accessing undeclared variables I use
if (typeof myVar != 'undefined')
This works fine but I'd like to stick another if statement in it. Something like converting this:
if (typeof myVar != 'undefined'){
if (myVar == "test"){}
}
to this:
if (typeof myVar != 'undefined' && myVar == "test")
Considering myVar
may be undefined, is this last code secure in every case of usage and every browser?
Is it possible that various statements inside an if ()
are not evaluated in the order they're written?
Can I assume myVar == "test"
will never be executed if myVar
is undefined?