JavaScript WeakSet Reference Last Updated : 18 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript WeakSet is used to store a collection of objects. It adapts the same properties as that of a set i.e. does not store duplicates. The major difference between WeakSet and a set is that a WeakSet is a collection of objects and not values of some particular type.Syntax:weakSet.function();Example: In this example, we will use the JavaScript weakSet() method. JavaScript // 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 console.log(A.has(object1)); Outputtrue The complete list of JavaScript WeakSet is listed below:JavaScript WeakSet Constructor: In JavaScript, a constructor gets called when an object is created using the new keyword.ConstructorDescriptionweakSet()A constructor gets called when an object is created using the new keyword.JavaScript WeakSet Properties: A JavaScript property is a member of an object that associates a key with a value. There is no static property in the weakSet only instance property.Instance Properties: An instance property is a property that has a new copy for every new instance of the class.Instance PropertyDescriptionconstructorReturn the wekaMap constructor function for the object.JavaScript WeakSet Method: JavaScript methods are actions that can be performed on objects.Instance Method: If the method is called on an instance of a WeakSet then it is called an instance method of WeakSet.Instance MethodDescriptionadd()Add an object at the end of an object WeakSet.delete()Delete a specific element from a weakSet object.has()Return a boolean value indicating whether an object is present in a weakSet or not. that Comment More infoAdvertise with us Next Article JavaScript WeakSet Reference K kartik Follow Improve Article Tags : JavaScript Web Technologies JavaScript-WeakSet Similar Reads JavaScript WeakMap Reference JavaScript WeakMap object in JavaScript is used to store the collection of objects (key-value pairs) in which keys are weakly referenced. The major difference between a WeakSet with a set is that a WeakSet is a collection of objects and not values of some particular type.Syntax:WeakMap.function();Ex 2 min read JavaScript WeakSet A WeakSet in JavaScript is a collection of unique objects where the values are weakly referenced. It works similarly to a Set, but the objects stored in a WeakSet can be garbage-collected when no longer in use.A WeakSet can only store objects, not primitive values like strings or numbers.Objects in 4 min read JavaScript weakSet add() Method Javascript weakSet.add() is used to add an object at the end of the object WeakSet. The WeakSet object lets you store weakly held objects in a collection. Syntax: weakSet.add(A);Parameters: This method accepts a single parameter value. value: This value will be added to the weakset object. Return Va 2 min read JavaScript weakSet has() Method JavaScript weakSet.has() method 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(value); Parameters: This method accepts a single parameter value. value: This valu 2 min read WeakSet vs WeakMap in JavaScript In JavaScript, there are two types of references strong and weak. The WeakSet and WeakMap are called weak references. Since these are weak references they do not prevent garbage collection if they are the only reference to the object in the memory. These objects are rarely used but are useful when w 2 min read Like