es6-cheatsheet icon indicating copy to clipboard operation
es6-cheatsheet copied to clipboard

I think let and const will actually be hoisted in their scope

Open DanielWLam opened this issue 8 years ago • 1 comments

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 avatar Jan 25 '17 10:01 DanielWLam

@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.

DrkSephy avatar Feb 18 '17 03:02 DrkSephy