Example 1 — Delete Returns true, Then false
Remove an entry, check that it is gone, and try to remove it a second time.
const wm = new WeakMap();
const key = { id: 1 };
wm.set(key, "data");
console.log(wm.delete(key)); // true
console.log(wm.has(key)); // false
console.log(wm.delete(key)); // false How It Works
- The first delete finds the entry.
wm.delete(key)removes the entry thatset()added, and reports it withtrue. - The entry is really gone. Right after the removal,
has(key)answersfalse. - The second delete has nothing to do. The same call a second time finds no entry, changes nothing, and returns
falseinstead of an error.

