ES2015 Scope & Hoisting - let & const
We'll learn how the new keywords 'let' and 'const' eliminate the problems of variable hoisting, scope limitations, and unintended reassignments. We'll show why 'var' should never be used again.
ES2015 introduces two new ways to declare variables. The keywords let
and const
. If you’re not familiar with these yet, here are the basics of these two keywords.
let
let
is similar to var
. It allows us to declare variables in our local scope. It’s used the same way, let x = 4;
. The differences are that let
is:
- not hoisted
- block-scoped
Not Hoisted
We’ve seen that variable declarations using var
get hoisted to the top of their scope.
Get hands-on with 1200+ tech skills courses.