Created
January 29, 2013 20:44
-
-
Save yangsu/4667648 to your computer and use it in GitHub Desktop.
JavaScript Hoisting
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
console.log(y === undefined); // "true" | |
var y = 3; | |
// will return a value of undefined | |
var myvar = "my value"; | |
(function() { | |
console.log(myvar); // undefined | |
var myvar = "local value"; | |
})(); | |
// this is equivalent | |
var myvar = "my value"; | |
(function() { | |
var myvar; | |
console.log(myvar); // undefined | |
myvar = "local value"; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment