Created
January 29, 2013 20:46
-
-
Save yangsu/4667668 to your computer and use it in GitHub Desktop.
JavaScript Scope
This file contains 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
// x is defined in the body of the if, but can be referenced outside | |
if (true) { | |
var x = 5; | |
} | |
console.log(x); | |
(function () { | |
var x = 10; | |
console.log(x); // 10 | |
})(); | |
console.log(x); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment