JavaScript | weakSet.has() with Examples
The weakSet.has() is an inbuilt function in JavaScript which is used to return a boolean value indicating whether an object is present in a weakSet or not. The WeakSet object lets you store weakly held objects in a collection.
Syntax:
weakSet.has(A);
Parameters: It accepts the parameter “A” which is a value going to be checked whether it is present in the weakSet object or not.
Return Values: It returns boolean value true if the element is present otherwise it returns false.
Code #1:
<script> // Constructing a weakSet() object const A = new WeakSet(); // Constructing new objects const object1 = {}; // Adding the new object to the weakSet A.add(object1); // Checking whether the new object is present // in the weakSet or not document.write(A.has(object1) +"<br>"); </script> |
Output:
true
Here output is true because the object “object1” is present in the WeakSet() object.
Code #2:
<script> // Constructing a weakSet() object const A = new WeakSet(); // Constructing new objects const object1 = {}; // Checking whether the new object is present // in the weakSet or not document.write(A.has(object1) +"<br>"); </script> |
Output:
false
Here output is false because the object “object1” is not present in the WeakSet() object.
Recommended Posts:
- JavaScript | console.log() with Examples
- JavaScript | weakMap.has() with Examples
- JavaScript | unescape() with examples
- JavaScript | parseFloat() with Examples
- JavaScript | weakSet.add() with Examples
- JavaScript | weakMap.set() with Examples
- JavaScript | parseInt() with Examples
- JavaScript | getPrototypeOf() with Examples
- JavaScript | uneval() with Examples
- JavaScript | typedArray.map() with Examples
- JavaScript | _.reduceRight() with Examples
- JavaScript | typedArray.name with Examples
- JavaScript | typedArray.every() with Examples
- JavaScript | typedArray.of() with Examples
- Javascript | _.reduce() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



