Note: Don’t confuse const
with mutable objects. As I said, you cannot assign some other value to the const variables, but you can modify the const
value. Constant Reference, Not Value:The other new keyword for variable declaration in ES6 is const, but it is often misinterpreted as being a “constant value”. Instead, in ES6 a const represents a constant reference to a value (the same is true in most languages, in fact). In other words, the pointer that the variable name is using cannot change in memory, but the thing the variable points to might change. For example,
‘use strict’;
const a = {};
a.a = 1;
is perfectly valid, because we are not changing what is assigned to a
, but we are changing the object pointed by a
.