8.4 Preventing mutations by making data immutable

We can prevent mutations of shared data by making that data immutable.

8.4 Preventing mutations by making data immutable - 图1 Background

For background on how to make data immutable in JavaScript, please refer to the following two chapters in this book:

8.4.1 How does immutability help with shared mutable state?

If data is immutable, it can be shared without any risks. In particular, there is no need to copy defensively.

8.4 Preventing mutations by making data immutable - 图2 Non-destructive updating is an important complement to immutable data

If we combine the two, immutable data becomes virtually as versatile as mutable data but without the associated risks.