Javatpoint Logo
Javatpoint Logo

JavaScript Set add() method

The JavaScript Set add() method is used to add a new object to the end of a WeakSet object.

Syntax

The add() method is represented by the following syntax:

Parameter

value - It represents the object to be added.

Return

The WeakSet object.

JavaScript Set add() method example

Here, we will understand add() method through various examples.

Example 1

Let's see an example to add object to WeakSet object.

Test it Now

Output:

true
true

Example 2

In this example, we will see whether we add the objects to WeakSet object without initializing them.

Test it Now

Output:

ReferenceError: obj is not defined






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA