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
const. If you’re not familiar with these yet, here are the basics of these two keywords.
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
- not hoisted
We’ve seen that variable declarations using
var get hoisted to the top of their scope.