ES2015 const is not about immutability
<span style="color: #333333;">const</span>
creates an immutable bindingTo make an object’s values immutable, use
Object.freeze()
. It has been around since ES5 and is widely available nowadays.<span class="keyword">const</span> foo = <span class="built_in">Object</span>.freeze({ <span class="string">'bar'</span>: <span class="number">27</span> }); foo.bar = <span class="number">42</span>; <span class="comment">// throws a TypeError exception in strict mode;</span> <span class="comment">// silently fails in sloppy mode</span>