Mid JavaScript

What are WeakMap and WeakSet?

They are collections that hold weak references to objects — allowing garbage collection if

no other reference exists.

Example:

let obj = {};

let wm = new WeakMap();

wm.set(obj, "value");

obj = null; // entry removed automatically

More from JavaScript Tutorial

All questions for this course