Immutability
non-ability to mutate
example:
var
mutableconst
immutableconst z = [4,5,6]
-> z[0]
mutable !!!Object.freeze(..)
is immutable, even the ..
partconst
is an immutable binding. so it cannot be bound to another value. Primitives in JS are immutable. Such as a number (3) or Strings ("foo") are primitives and therefore immutable. z
is a reference to value. arrays and objects for example in JS are references and passed as such. Object.freeze is in ES5. all properties are read only. But it's shallow immutability.So a member array's items can still be changed...
For deeper immutability you need libraries. There are lots of great utilities for this.
Immutable binding vs immutable valuesconst
only gives immutable binding, which is less interesting. Immutable values are more important, so these values cannot be changed "from a distance" from another part (e.g. utility) in our app.