ECMAScript const objects are references
A note about const in JavaScript, which is not a constant, but a way to solve some JavaScript problems related to block scopes.
A note about const in JavaScript, which is not a constant, but a way to solve some JavaScript problems related to block scopes.
Read more:
The
constdeclaration creates a read-only reference to a value. It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its parameters) can be altered. (edited)
ES2015 const is not about immutability
constis not about immutability
constmakes the contract that no rebinding will happen
Constant Variables in JavaScript, or: When "const" Isn't Constant
Unfortunately, the name of the
constkeyword might be misleading. In JavaScript, const does not mean constant, but one-time assignment. It's a subtle yet important distinction. Let's see what one-time assignment means..
Have thoughts about this post? Let's discuss it on X!
Alex Razbakov
Building community platforms, teaching salsa, writing to find my people.