DEV Community

Discussion on: Understanding Hoisting in JavaScript

Collapse
 
imwiss profile image
Wissam A

Thanks for the feedback Daniel!

That's true, ES6 is the future and is what most developers will be using moving forward. That said, it's not entirely true that hoisting doesn't apply to let and const variables. It doesn't apply the same way as for var, but these let and const variables are still hoisted. The difference though is that they cannot be accessed until the assignment is done at runtime.

From ES6's documentation:

The variables are created when their containing Lexical Environment is instantiated but may not be accessed in any way until the variable’s LexicalBinding is evaluated.

At the end of the day, it's a small technicality where the interpreter applies hoisting to these variables on the compile run but they'll throw reference errors when accessed before the assignment happens, so your point is right :)

I'll update my post, thanks!