Say you have a variable:
var x = [1,2]
If it is a mutable object, you could do:
x.append(3)
x
>> [1,2,3]
But if it is immutable, and you wanted to change the value of x, you would effectively have to do:
// init x
var x = [1,2]
// add a 3 to x
x = [1,2,3]
x
>> [1,2,3]
What's the difference between mutability and just changing the variable?
My best guess is that when you do append(3) it is modifying a reference to the same variable in memory, but when you x = [1,2,3], you possibly declaring a new variable x, referencing a new block in memory, and deallocating the old block that x=[1,2] occupied.
It seems like immutable variables should not be able to change. But many times we want immutable variables to change. For example, in React, state variables are considered immutable. But the point of having state is so that the variables can change. So to change the values of them you need to go through these very roundabout ways, like calling setState(), and feeding it callback functions if you want to do something like append an element to a list.