This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
The deref() method of WeakRef instances returns this WeakRef's target value, or undefined if the target value has been garbage-collected.
deref()
None.
The target value of the WeakRef, which is either an object or a non-registered symbol. Returns undefined if the value has been garbage-collected.
See the Notes on WeakRefs section of the WeakRef page for some important notes.
See the Examples section of the WeakRef page for the complete example.
const tick = () => {
// Get the element from the weak reference, if it still exists
const element = this.ref.deref();
if (element) {
element.textContent = ++this.count;
} else {
// The element doesn't exist anymore
console.log("The element is gone.");
this.stop();
this.ref = null;
}
};
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
deref |
84 | 84 | 79 | 70 | 14.1 | 84 | 79 | 60 | 14.5 | 14.0 | 84 | 14.5 | 1.0.0 | 1.0 | 14.6.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref