Skip to content

Issue on explanation accuracy about const #1377

@Neo42

Description

@Neo42

Variables declared using const are called “constants”. They cannot be changed. An attempt to do so would cause an error...

The explanation in the Variable chapter is a little unclear. Because, as far as I know, you can actually change the value of a const. For example,

const foo = {};
foo.bar = 42;
console.log(foo.bar); // 42

I borrowed this example from @mathiasbynens 's great blog post on es6 const written a few years ago. He said const can change but no "rebinding will happen". And I think by "rebinding", he meant "reassignment".

So it is probably better to just change "cannot be changed" to "cannot be reassigned".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions