WeakRef() constructor
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.
* Some parts of this feature may have varying levels of support.
>The WeakRef() constructor creates WeakRef objects.
Syntax
jsnew WeakRef(target)
Note:
WeakRef() can only be constructed with new. Attempting to call it without new throws a TypeError.
Parameters
target-
The target value the WeakRef should refer to (also called the referent). Must be an object or a non-registered symbol.
Return value
A new WeakRef object referring to the given target value.
Exceptions
TypeError-
Thrown if
targetis not an object or a non-registered symbol.
Examples
>Creating a new WeakRef object
See the main WeakRef
page for a complete example.
class Counter {
constructor(element) {
// Remember a weak reference to a DOM element
this.ref = new WeakRef(element);
this.start();
}
}
Specifications
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-weak-ref-constructor > |
Browser compatibility
See also
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Jul 10, 2025 by MDN contributors.
View this page on GitHub • Report a problem with this content