Learning JavaScript ES6: Part 1: Let and Const

Learning JavaScript ES6

JavaScript ES6 (ECMAScript 6) is a newer specification for JavaScript introduced in 2015 and adopted by most browsers starting in mid-2016. It added new syntax and a greater ability to use object-oriented programming in JavaScript.

Let and Const

The keyword var was introduced with the first version of JavaScript. It described any variable used. If a value was stored, it used var.

ES6 changes things. It introduces two new keywords: let and const. Now, instead of using var, these new keywords can be used to describe the mutability of the values.


If the value of a variable might change, the keyword let can be used. It takes the place of var and describes something that can or will change. It is mutable.


If the value of a variable will not change, the keyword const can be used. Its value is a constant once created. It is immutable.

Let or Const?

The keywords let and const give developers greater flexibility when defining values. For those that will not change, the keyword const can be very helpful. Once defined that way, JavaScript will throw an error if any attempts are made to change its value. The keyword let also acts as a balance for const and a replacement for var.

Play with the example on Repl.it!