Skip to content

Instantly share code, notes, and snippets.

@yangsu
Created January 29, 2013 20:44
Show Gist options
  • Save yangsu/4667648 to your computer and use it in GitHub Desktop.
Save yangsu/4667648 to your computer and use it in GitHub Desktop.
JavaScript Hoisting
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