WeakRef() constructor
The WeakRef() constructor creates WeakRef objects.
The **`WeakRef()`** constructor creates WeakRef objects.
## Syntax
```js-nolint
new WeakRef(target)
```
> [!NOTE]
> `WeakRef()` can only be constructed with [`new`](/docs/Web/JavaScript/Reference/Operators/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](/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry).
### Return value
A new `WeakRef` object referring to the given target value.
### Exceptions
- TypeError
- : Thrown if `target` is not an object or a [non-registered symbol](/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry).
## Examples
### Creating a new WeakRef object
See the main [`WeakRef`](/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#examples)
page for a complete example.
```js
class Counter {
constructor(element) {
// Remember a weak reference to a DOM element
this.ref = new WeakRef(element);
this.start();
}
}
```
## Specifications
## Browser compatibility
## See also
- WeakRef
Cite this
"WeakRef() constructor". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/WeakRef JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy