Tip 15 Create Maps Without Side Effects

In this tip, you’ll learn how to avoid side effects by creating new maps from an array of pairs.

Up to this point, you’ve always worked on a single instance of a map. You’ve either added data or removed data directly from an instance of a Map object.

Working on the instance of a map can lead to a few problems. How do you create copies of a map? How can you make changes without side effects?

Fortunately, you can solve those problems by applying a few principles you’ve learned from arrays and objects.

To start, look at an example that combines the problems of copying and mutations: applying a set of defaults to a map.

In your pet adoption code, you have filters that users have selected, but perhaps ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.