Created
March 1, 2012 22:20
-
-
Save easierbycode/1953645 to your computer and use it in GitHub Desktop.
auto global
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It?s treated like: var x = (y = 1); thus, ?y=1? creates an auto-global since there?s no binding ?var? statement for it. then that value gets copied into properly defined local var ?x?. | |
(function(){ | |
var x = y = 1; | |
})(); | |
alert(x); // undefined | |
alert(y); // 1 -- oops, auto-global! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment