When using strict mode, exceptions are thrown when accessing undefined variables.
Consider the following:
"use strict";
alert(typeof mistypedVaraible + " one");
alert(mistypedVaraible + " two");
only the first alert fires because an exception is thrown when trying to access the undefined variable in the second alert. So define it before the second alert:
"use strict";
alert(typeof mistypedVaraible + " one");
if(typeof mistypedVaraible == "undefined") { var mistypedVaraible; }
alert(mistypedVaraible + " two");
Both alerts fire, because the test for undefined has declared the variable.
But if the test fails and the variable DOES NOT get defined, the 2nd alert fires anyways, as if the "if" block got executed to define the variable:
"use strict";
alert(typeof mistypedVaraible + " one");
if(typeof mistypedVaraible != "undefined") { var mistypedVaraible; }
alert(mistypedVaraible + " two");
What's going on here?