Created
June 16, 2019 21:23
-
-
Save reime005/65cdaae615f86b0f23d292336fea135c to your computer and use it in GitHub Desktop.
JavaScript hoisting example
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
foo(); // works because hoisted | |
var someVariable = 42; | |
// would not be hoisted: var foo = function() ... | |
function foo() { | |
console.log(someVariable); // undefined | |
var someVariable = 91; | |
console.log(someVariable); // 91 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment