Skip to content

Instantly share code, notes, and snippets.

@andy-williams
Last active January 12, 2016 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy-williams/2ef864adf8ec9678f50e to your computer and use it in GitHub Desktop.
Save andy-williams/2ef864adf8ec9678f50e to your computer and use it in GitHub Desktop.
(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);
(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