Skip to content

Instantly share code, notes, and snippets.

@marthakelly
Last active August 12, 2020 17:05
Show Gist options
  • Save marthakelly/d4bedc6f3174d4cc28c5954f51eda04e to your computer and use it in GitHub Desktop.
Save marthakelly/d4bedc6f3174d4cc28c5954f51eda04e to your computer and use it in GitHub Desktop.
/*
* 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