Creating a WeakMap object

suggest change

A WeakMap stores key/value pairs. Unlike a Map, its keys must be objects and are held weakly. If nothing else still refers to a key, the garbage collector may remove that entry. Using a primitive as a key throws TypeError.

The constructor takes an optional iterable of pairs (for example an array). Each pair is a two-element array.

const o1 = {a: 1, b: 2},
      o2 = {};

const weakmap = new WeakMap([[o1, true], [o2, o1]]);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents