Last active
August 12, 2020 17:05
-
-
Save marthakelly/d4bedc6f3174d4cc28c5954f51eda04e to your computer and use it in GitHub Desktop.
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
/* | |
* Variables declared with var are hoisted and initialized to undefined. | |
* Variables declared with let, const, are hoisted but remain uninitialized. | |
*/ | |
function letsFigureOutHoisting() { | |
// VARIABLE NAMES ARE HOISTED PHYSICALLY HERE, AT THE TOP OF THE FUNCTION | |
// we're referencing these variables BEFORE they are assigned values! | |
console.log(cat); // will throw a ReferenceError | |
console.log(dog); // will evaluate to undefined | |
const cat = 'cat'; | |
var dog = 'dog'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment