O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

1

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required