66
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.
Output:
true true
Example 2
In this example, we will see whether we add the objects to WeakSet object without initializing them.
Output:
ReferenceError: obj is not defined
Next TopicWeakSet delete() Method