DEV Community

Discussion on: Coding Concepts - Hoisting

Collapse
 
fikash profile image
Raffi Nakashian

Interesting that "let" and "const" did not inherit the hoisting behavior. I've come to understand that "var" should not be used going forward as of ES6 in favor of let and const... was this a deliberate decision to remove the hoisting behavior from Javascript altogether in time?

Collapse
 
jamesthomson profile image
James Thomson

The main reason for this is because let and const are block scoped. var on the other hand is not and therefore can be hoisted up to the global context (as long as 'use strict' is not present).

Collapse
 
chris_bertrand profile image
Chris Bertrand

Indeed, thanks for the added clarification James. I'll add that in. I'll blockquote you! 😊