On 17 April 2015 at 14:17, Mathias Bynens <[email protected]> wrote:

> On Fri, Apr 17, 2015 at 7:53 AM, Glen Huang <[email protected]> wrote:
> > I've completely replaced "var" with "let" in my es 2015 code, but I
> noticed most variables I introduced never change.
>
> Note that `const` has nothing to do with the value of a variable
> changing or not. It can still change:
>
>     const foo = {};
>     foo.bar = 42; // does not throw
>
> `const` indicates the *binding* is constant, i.e. there will be no
> reassignments etc.
>

I have to nitpick on this. In usual nomenclature of programming language
semantics the "value" in question is the _reference_ to the object (for
types with reference semantics), and that does not change. That the object
itself actually can be mutable is a separate property.

The idea that const somehow applies transitively is a specific idiosyncrasy
of low-level languages like C and friends, that make flattening and copying
of mutable objects an implicit part of their semantics. It is not the norm,
and actually rather contorted semantically.

/Andreas


> In my post-ES6 code, I use `const` by default, falling back to `let`
> if I explicitly need rebinding. `var` is for legacy code.
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to