ECMAScript 6 has these very similar collections: Set
and WeakSet
. What is the difference between them?
The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. This means that an object in WeakSet can be garbage collected if there is no other reference to it.
Other differences (or rather side-effects) are: