The const declaration 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 properties) can be altered.
All types except objects define immutable values (that is, values which can't be changed). For example (and unlike in C), Strings are immutable. We refer to values of these types as "primitive values".
This gives people the impression that const works differently for primitive values and objects - it's just that the binding is immutable - not the value which why you can still modify the internals of objects (and arrays which are objects).
Nice post.....
I don't understand the the const variable explanation...or is it a typo?
Thank you for your reply - I tried to make the explanation a touch easier to understand, but I guess it ended up being more confusing 😅
Probably should have been
but even that isn't correct.
Quote
The wrinkle is that
Quote:
This gives people the impression that
const
works differently for primitive values and objects - it's just that the binding is immutable - not the value which why you can still modify the internals of objects (and arrays which are objects).Thank you for helping me out! Awesome explanation!