WeakSet - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

non-registered symbols

A WeakSet is a collection of garbage-collectable values, including objects and non-registered symbols. A value in the WeakSet may only occur once. It is unique in the WeakSet's collection.

primitive data types

Values of WeakSets must be garbage-collectable. Most primitive data types can be arbitrarily created and don't have a lifetime, so they cannot be stored. Objects and non-registered symbols can be stored because they are

WeakSet.prototype.constructor

The constructor function that created the instance object. For WeakSet instances, the initial value is the WeakSet constructor.

[Symbol.toStringTag]

The initial value of the [Symbol.toStringTag] property is the string "WeakSet". This property is used in Object.prototype.toString().

Object.prototype.toString()

The initial value of the [Symbol.toStringTag] property is the string "WeakSet". This property is used in Object.prototype.toString().

WeakSet.prototype.add()

Inserts the specified value into this set, if it is not already present.

WeakSet.prototype.delete()

Inserts the specified value into this set, if it is not already present.

WeakSet.prototype.has()

Inserts the specified value into this set, if it is not already present.

Detecting circular references

Functions that call themselves recursively need a way of guarding against circular data structures by tracking which objects have already been processed.

Learn how to contribute

This page was last modified on Sep 22, 2025 by MDN contributors.

[Symbol.hasInstance]()

__defineGetter__()

__defineSetter__()

__lookupGetter__()

__lookupSetter__()

propertyIsEnumerable()