Use-Cases of this Tutorial
- Know about immutable data that can be applied in Javascript.
When you're the only developer working on an application, the concept of data immutability may not sound important to you.
But imagine the web application is huge, and you're one of several developers working on it. You have created an array in your code, and the other developer needs access to this array. The other developer does something with your data, and changes your original array. Now because your array is changed, your feature in the application stops to work. You get stressed and tell the other developer to "please do not change my array" or "create a new copy of the array and work on that".
Such scenarios are common when many people get involved in development. Each developer is responsible for his own module, but there will always be times when a developer will need access to data created by another developer. In such cases the original developer needs to "freeze" his data so that the other developer cannot change it.
Data immutability holds an important position in software development, and it is gradually entering Javascript development too.
The below video gives an introduction as to what is data immutability and its importance. It will tell how you can create immutable data structures, keeping in mind "time to create the data structure" and "space occupied by the data structure". The tree data structure can be used to create immutable data structures in Javascript. However in practice you don't need to create such data structures by yourself — there are external libraries such as Immutable JS that can help to create immutable objects.