Last active
August 29, 2015 14:23
-
-
Save codeimpossible/7d9eba8b2fc7c76ae286 to your computer and use it in GitHub Desktop.
Variable hoisting
This file contains hidden or 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
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. |
This file contains hidden or 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
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