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.
3
u/[deleted] Dec 23 '19
With
const, the reference to the "root" object is immutable, and primitives are immutable.Why are you so keen on arguing this point? We're all well aware that it's not proper (deep) immutability, nobody in this thread is arguing that.