Skip to content Skip to sidebar Skip to footer

Delete Or Override Const Variables In Javascript Harmony / Ecmascript 6

Reading and tinkering with the new features offered by ECMAScript 6. The new 'const' statement for writing constant variables is a nifty feature, which adds features to an already

Solution 1:

It is not possible to redefine variables declared using const.

However, const is block-scoped. To address the issue you describe, when testing some code in the console all you would have to do is wrap your script in { and }:

{ const x = 1; }
{ const x = 2; }

Note that many browsers that already support the const keyword do not yet support block-scoped constants so the example above will fail in Chrome and Firefox (See Kangax's compatibility table for more).

Solution 2:

FYI - const a = {}; var b = new a; a = 33; I just changed the const 'a' back to a var.

Post a Comment for "Delete Or Override Const Variables In Javascript Harmony / Ecmascript 6"