JavaScript question detail
What are the differences between WeakMap and Map
The main difference is that references to key objects in Map are strong while references to key objects in WeakMap are weak. i.e, A key object in WeakMap can be garbage collected if there is no other reference to it.
Other differences are,
Mapcan store any key type whereasWeakMapcan store only collections of key objectsWeakMapdoes not have size property unlikeMapWeakMapdoes not have methods such as clear, keys, values, entries, forEach.WeakMapis not iterable.