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

Related questions

0 votes
0 votes
asked Dec 2, 2022 in JavaScript by john ganales
0 votes
asked Dec 1, 2022 in JavaScript by john ganales
...