HTML and CSS Reference
An immutable object is an object that cannot be changed after it is first created.
Even when these appear to change, as in the examples below, in reality a new
object is being created.
In order to see immutability in action, declare a new variable called t , and assign it the
value of s :
> t = s
We can now print out the value of t , and also confirm that t and s are equal:
> s == t
What should happen if we now modify the string held against the variable s ? We can ap-
pend to the string value using the += operator:
> s += 'test'
If you now print out the value of s you will see that the string's value appears to have
Despite this, if you print out the value of t it has retained its old value: