WeakRef() vs WeakRef.prototype.deref()
WeakRef() and WeakRef.prototype.deref() are both JavaScript WeakRef APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. WeakRef(): Creates a weak reference. Its syntax is new WeakRef(target). WeakRef.prototype.deref(): Returns the referenced object or undefined. Its syntax is weakRef.deref(). Example of WeakRef(): new WeakRef({x:1}). Example of WeakRef.prototype.deref(): ref.deref() // {x:1} or undefined. Read the full references for WeakRef() and WeakRef.prototype.deref() to see edge cases, time complexity, browser support, and the mistakes developers most often make with each. Other WeakRef APIs worth comparing: WeakSet.prototype.has(), WeakSet.prototype.delete(), WeakMap.prototype.has(), WeakMap.prototype.delete(). Both belong to the WeakRef category in the JS Reference documentation, which covers 6 entries in total. Try both in the JavaScript playground to see the behavioral difference live.