es6-cheatsheet
es6-cheatsheet copied to clipboard
I think let and const will actually be hoisted in their scope
when you declare a variable with var, it will be hoisted and set value as undefined. I think let and const are so similar but they are passed the default value 'ReferenceError'
@DanielWLam you are correct. let
and const
declarations are hoisted, however if you try to reference these variables before they are declared, a ReferenceError
is thrown (regardless of the hoisting. This is also known as the Temporal Dead Zone.