Hint
Map holds a STRONG reference to keys — prevents GC. WeakMap holds a WEAK reference — key can be collected. That's why WeakMap has no .size or iteration.
let obj = { data: 'sensitive' };
const weakMap = new WeakMap();
const strongMap = new Map();
weakMap.set(obj, 'weak-value');
strongMap.set(obj, 'strong-value');
console.log(weakMap.has(obj));
console.log(strongMap.has(obj));
// After obj is dereferenced:
obj = null;
// WeakMap may release the entry (GC timing non-deterministic)
console.log(strongMap.size);true true 1
Explanation: Before null: both have the entry. After obj = null: WeakMap no longer prevents GC of the original object — entry may vanish. Map holds a strong reference — keeps the entry and size = 1. (WeakMap size is always inaccessible.)
Key Insight: Map holds a STRONG reference to keys — prevents GC. WeakMap holds a WEAK reference — key can be collected. That's why WeakMap has no .size or iteration.