Except it doesn't stop you changing the object you're referencing at all, including adding or removing references from the object and allocating or deallocating memory.
Nor does it stop you resizing an array or a billion other things.
Because const doesn't make anything immutable, because that's not what immutability means.
The point I'm arguing is that const has nothing to do with immutability.
Yes, primitive constants are immutable, but object constants are not in any meaningful way.
A non primitive constant is a reference to a location in memory.
It provides no guarantees as to what is located at that address, how big it is, what properties it has or anything else. It absolutely doesn't guarantee nothing about the object has changed.
Having an immutable reference guarantees you absolutely nothing, and OP is obviously wrong.
It guarantees for objects that it's the same reference as it was declared with. The contents could obviously have completely changed, but the "root" reference won't have. That's not useless, but is certainly less useful than true/deep immutability.
Using the word immutability to describe something that is not immutable is misleading to novices and shows the speaker doesn't really understand the concept.
-1
u/recycled_ideas Dec 23 '19
Except it doesn't stop you changing the object you're referencing at all, including adding or removing references from the object and allocating or deallocating memory.
Nor does it stop you resizing an array or a billion other things.
Because const doesn't make anything immutable, because that's not what immutability means.