Hi Bill,
Keith Ensign
31

A quick note about the immutability of const (or lack thereof)

I’m glad you found my article helpful, I just wanted to clarify a small point regarding const in ES2015. Unfortunately, a const can indeed be mutated.

The following is perfectly legal in ES2015:

const foo = [];
foo.push(‘bar’);

All the const declaration does is prevent re-assignment which is not the same as preventing mutation.

The following works fine in ES2015 as well and is totally legal:

const foo= { bar: ‘bar’ };
foo.bar = ‘baz’;

These days, I tend to use Immutable.js to get true immutability.