WeakSet() constructor
Baseline Widely availableThis feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
>The WeakSet() constructor creates WeakSet objects.
Syntax
jsnew WeakSet()
new WeakSet(iterable)
Note:
WeakSet() can only be constructed with new. Attempting to call it without new throws a TypeError.
Parameters
iterableOptional-
If an iterable object is passed, all of its elements will be added to the new
WeakSet.nullis treated asundefined.
Examples
>Using the WeakSet object
jsconst ws = new WeakSet();
const foo = {};
const bar = {};
ws.add(foo);
ws.add(bar);
ws.has(foo); // true
ws.has(bar); // true
ws.delete(foo); // removes foo from the set
ws.has(foo); // false, foo has been removed
ws.has(bar); // true, bar is retained
Note that foo !== bar. While they are similar objects, they are not
the same object. And so they are both added to the set.
Specifications
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-weakset-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 Oct 26, 2026 by MDN contributors.
View this page on GitHub • Report a problem with this content