JS Built-ins
WeakRefderefbeginner

WeakRef.deref β€” returns original object

πŸ“– Usage Example
let obj = { x: 1 }
const ref = new WeakRef(obj)
ref.deref()?.x  // β†’ 1

deref() returns the referenced object, or undefined if it has been garbage collected.

WeakRef deref

After const r = new WeakRef(o), r.deref() === o is true.

Challenge: Verify deref returns the original object.

πŸ’‘ Hints (1)
  • β€’ deref() returns the object that was passed to the WeakRef constructor.