JavaScript theorytheory 0/50 · 0%
Data · medium

25. Map, Set and WeakMap

Keyed collections beyond plain objects.

`Map` accepts any key type and keeps insertion order with a real `size`. `Set` stores unique values. `WeakMap` holds keys weakly so entries can be garbage collected.

const seen = new Set(addresses.map((a) => a.toLowerCase()));
const cache = new Map(); cache.set(provider, data);

Use a Map when keys are dynamic or non-string; use an object for fixed, known shapes.

Check your understanding

  1. 1. What key types does a Map accept?

  2. 2. What does a Set guarantee?

  3. 3. Why use a WeakMap?