-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Description
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); // 42I 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
Labels
No labels