0 votes
in JavaScript by
What are the differences between WeakSet and Set?

1 Answer

0 votes
by

The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it. Other differences are,

  1. Sets can store any value Whereas WeakSets can store only collections of objects
  2. WeakSet does not have size property unlike Set
  3. WeakSet does not have methods such as clear, keys, values, entries, forEach.
  4. WeakSet is not iterable.

Related questions

0 votes
+1 vote
asked Mar 22, 2021 in JavaScript by Robindeniel
0 votes
asked Dec 1, 2022 in JavaScript by john ganales
...