Last active
January 12, 2016 16:46
-
-
Save andy-williams/2ef864adf8ec9678f50e 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
(function() { | |
myVar = 1; | |
console.log("myVar should be 1: " + myVar); // should be 1 | |
setTimeout(function() { | |
console.log("myVar should be 1, but isn't: " + myVar); // should be 1, but isn't | |
}, 100); | |
})(); | |
(function() { | |
myVar = 2; | |
})(); | |
console.log(myVar); |
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
(function() { | |
console.log(myVar); // undefined | |
var myVar = 1; | |
console.log(myVar); // OK | |
(function() { | |
console.log(myVar); // OK | |
})(); | |
})(); | |
console.log(myVar); // Ref Error: myVar not defined | |
(function() { | |
for(var myVar1 = 1; myVar1 < 2; myVar1++) { | |
console.log(myVar1); // OK | |
} | |
console.log(myVar1); // It's still HERE ! | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment