Creating a WeakSet object

suggest change

A WeakSet stores objects. Unlike a Set, it cannot store primitives such as numbers or strings; add throws TypeError for those. References are weak: if nothing else still refers to an object in the set, the garbage collector may remove it.

The WeakSet constructor has an optional parameter, which can be any iterable object (for example an array). All of its elements will be added to the created WeakSet.

const obj1 = {},
      obj2 = {};

const weakset = new WeakSet([obj1, obj2]);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents