JS Built-ins
WeakRefderefbeginner

WeakRef.deref β€” array reference

πŸ“– Usage Example
const cache = new WeakRef(computeExpensiveResult())
const result = cache.deref() ?? recompute()

Use deref() with nullish coalescing to fall back to recomputation if the object was GC'd.

WeakRef with Array

You can hold a weak reference to an array. deref() returns the same array.

Challenge: Verify deref on an array WeakRef.

πŸ’‘ Hints (1)
  • β€’ Arrays are objects so they can be held in a WeakRef.