Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Last active August 29, 2015 14:23
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 codeimpossible/7d9eba8b2fc7c76ae286 to your computer and use it in GitHub Desktop.
Save codeimpossible/7d9eba8b2fc7c76ae286 to your computer and use it in GitHub Desktop.
Variable hoisting
var variable = "global";
function doSomething() {
console.log(variable);
var variable = 'local';
console.log(variable);
}
doSomething();
// output
// ----------------
// undefined
// "local"
//
// "2-hoisted.js" is what the compiler ran.
var variable = "global";
function doSomething() {
var variable;
console.log(variable);
variable = 'local';
console.log(variable);
}
doSomething();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment