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

js
new 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 target is not an object or a non-registered symbol.

Examples

Creating a new WeakRef object

See the main WeakRef 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

Specification
ECMAScript® 2027 Language Specification
# sec-weak-ref-constructor

Browser compatibility

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
WeakRef() constructor
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 14.6 (Release date: 2020-07-21)
footnote Full support
Non-registered symbol as target
Chrome – Full support
Chrome 109 (Release date: 2023-01-10)
footnote Full support
Edge – Full support
Edge 109 (Release date: 2023-01-12)
footnote Full support
Firefox – Full support
Firefox 146 (Release date: 2025-12-09)
footnote Full support
Opera – Full support
Opera 95 (Release date: 2023-02-01)
footnote Full support
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 109 (Release date: 2023-01-10)
footnote Full support
Firefox for Android – Full support
Firefox for Android 146 (Release date: 2025-12-09)
footnote Full support
Opera Android – Full support
Opera Android 74 (Release date: 2023-03-13)
footnote Full support
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 21 (Release date: 2023-05-19)
footnote Full support
WebView Android – Full support
WebView Android 109 (Release date: 2023-01-10)
footnote Full support
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.28 (Release date: 2022-11-13)
footnote Full support
Node.js – Full support
Node.js 20 (Release date: 2023-04-18)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also