Explain the WeakMap and WeakSet objects.

WeakMap and WeakSet store weak references to objects, allowing garbage collection to occur when there are no other references. This is useful for cases where you need temporary object references without preventing garbage collection. Unlike regular maps and sets, weak collections only allow object keys, not primitives.

const wm = new WeakMap();
let obj = { name: "Alice" };
wm.set(obj, "value");
obj = null; // now eligible for garbage collection