8.3 Avoiding mutations by updating non-destructively
We can avoid mutations if we only update data non-destructively.
Background
For more information on updating data, see §7 “Updating data destructively and non-destructively”.
8.3.1 How does non-destructive updating help with shared mutable state?
With non-destructive updating, sharing data becomes unproblematic, because we never mutate the shared data. (This only works if everyone that accesses the data does that!)
Intriguingly, copying data becomes trivially simple:
const original = {city: 'Berlin', country: 'Germany'};
const copy = original;
This works, because we are only making non-destructive changes and are therefore copying the data on demand.