Hey, just learned a new phrase today: Temporal Dead Zone
So just to put it in my own words, so I can try to remember it going forward:
When we create a variable with var
in javascript, this hoists the variable and declares it as undefined at the top of the scope, and then when the line of code is hit it will re-assign the variable with it’s value. So if we call the variable name before that line of code that declares the variable, it will return undefined
because the variable was created as undefined as explained above
Const and let do not do this, and the variable is only created with the value (no hoisting here!). So if we would call the const or let above where it was defined we will get an Uncaught Reference error, the variable is not defined. This area above the declaration of the const or let variable is called the Temporal Dead Zone!
Got it? Hope so 🙂