Created
June 11, 2010 05:50
-
-
Save hozaka/434099 to your computer and use it in GitHub Desktop.
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
var i = "initialized"; | |
function test() { | |
var i = 0; | |
for (i in [1, 2, 3]) { console.log(i) }; | |
} | |
test(); | |
console.log(i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 4 narrows the scope of var i. If you remove that line, the global var i will be changed after test() is called.
It's a feature in ECMAScript to change global variable value in for..in loop like this according to its specification.