Lesson 4. Declaring variables with let
After reading lesson 4, you will
- Understand how scope works with let and how it differs from var
- Understand the difference between block scope and function scope
- Understand how let variables are hoisted
In the history of JavaScript, variables have always been declared using the keyword var.[1] ES6 introduces two new ways to declare variables, with the let and const keywords.[2] Both of these work slightly differently than variables declared with var. There are two primary differences with let:
Actually, in non-strict mode, it was possible to create a new variable while completely omitting the var declaration altogether. This, however, created a global, usually unbeknownst to the author, leading ...
Get Get Programming with JavaScript Next now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.