This is a common confusion with immutability. There's a difference between an immutable value and an immutable reference.
For example, say you have x = 10
. You can't do something like 10 = 20
to change the value of x
. The 10
is immutable. You can do x = 20
, unless x
is declared to be immutable. But that doesn't change the value of 10
, just the value of x
.
On the other hand, you can have const x = SomeObject()
, where you can change stuff inside SomeObject
, but you can't reassign x
to point to a different object.
In most languages, literals likeValues of value types (like numbers and strings in most languages) are immutable, but variables aren't unless declared to be such, even variables pointing to immutable values.