Why is immutability so important (or needed) in JavaScript?

I am currently working on React JS and React Native frameworks. On the half way road I came across Immutability or the Immutable-JS library, when I was reading about Facebook’s Flux and Redux implementation.

The question is, why is immutability so important? What is wrong in mutating objects? Doesn’t it make things simple?

Giving an example, let us consider a simple News reader app with the opening screen being a list view of news headlines.

If I set say an array of objects with a value initially I can’t manipulate it. That’s what immutability principle says, right? (Correct me if I am wrong.)
But, what if I have a new News object that has to be updated? In usual case, I could have just added the object to the array.
How do I achieve in this case? Delete the store and recreate it?
Isn’t adding an object to the array a less expensive operation?

12 Answers
12

Leave a Comment