WeakRef.prototype.deref()
Baseline Widely available
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.
Syntax
js
deref()
Parameters
None.
Return value
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.
Description
See the Notes on WeakRefs section of the WeakRef
page for some important notes.
Examples
Using deref()
See the Examples
section of the WeakRef
page for the complete example.
js
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;
}
};
Specifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weak-ref.prototype.deref |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
deref |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.