Q28: What is the difference between Map, Set, WeakMap, and WeakSet?
Map: Key-value store accepting any data type key.Set: Collection of unique values.WeakMap/WeakSet: Hold garbage-collectable weak references strictly to objects/symbols. Their keys/elements are non-enumerable.
Key Takeaways
Mapsupports keys of any type;WeakMapkeys MUST be objects/symbols.WeakMapreferences do not prevent garbage collection if no other references exist.
Knowledge Check
Why are WeakMap keys non-enumerable?