Immutability

In notebook:
FrontEndMasters Functional light
Created at:
2016-09-23
Updated:
2016-09-23
Tags:
Functional Programming JavaScript Fundamentals
non-ability to mutate

example:

​var​ mutable
​const​ immutable
​const z = [4,5,6]​ -> ​z[0]​ mutable !!!

​Object.freeze(..)​ is immutable, even the ​..​ part
​const​ 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 values

​const​ 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.