0 votes
in JavaScript by
What is a WeakSet?

1 Answer

0 votes
by

WeakSet is used to store a collection of weakly(weak references) held objects. The syntax would be as follows,

new WeakSet([iterable]);

Let's see the below example to explain it's behavior,

var ws = new WeakSet();
var user = {};
ws.add(user);
ws.has(user); // true
ws.delete(user); // removes user from the set
ws.has(user); // false, user has been removed
...