Loading topic
const does not freeze a value. Here you will learn the most common tool for updating data without mutation: making a new object or array that s6 min readmap and filter to transform arrays without mutation. You should also be comfortable running JavaScript in Node.js 20 or later, or in a current browser. Every examp6 min readmap and filter return new arrays without touching the original. Both were covered in earlier chapters. Here we combine them to change a value buried several levels deep inside a state obje5 min readmap and filter, and promised yourself never to write state.user.name = .... Promises break, though, especially in a large codebase with many contributors. Object.freeze lets the JavaScript engine enforce the rule for you6 min readDate, Map, and Set, and with try/catch. All examples run in Node.js 17 or later and in every cu5 min readstructuredClone makes a full deep copy. Here we look at what those nested updates produce in memory. The new state reuses most of the old one. That reuse is called structural sharing, and 6 min readmap, and filter. It also builds on structural sharing from the previous chapter, which copies only the objects along a changed path and reuses everything 6 min read... that is easy to get wrong. Immer is a small library that lets you write ordinary6 min readnpm install immutable and run each snippet as an ES 7 min readObject.freeze, structuredClone, structural sharing, reference equality, and Immer's produce. Here we compare these tools by what they6 min read