JS Built-ins
WeakMapsetbeginner

WeakMap.prototype.set() β€” returns WeakMap

πŸ“– Usage Example
const wm = new WeakMap()
const k = {}
wm.set(k, 'hello')
wm.set(k, 'world')
wm.get(k)  // β†’ 'world'

Calling set() with the same key overwrites the previous value.

WeakMap set() Chaining

wm.set(k, 1) returns the WeakMap itself, enabling chaining.

Challenge: Verify set returns the WeakMap.

πŸ’‘ Hints (1)
  • β€’ Like Map.set(), WeakMap.set() returns the map itself.