WeakMap & WeakSet
What is the key characteristic that distinguishes WeakMap from Map in JavaScript?
The key characteristic of WeakMap is its handling of object references: 1) WeakMap only accepts objects as keys, not primitive values, 2) It holds these object keys with weak references, allowing them to be garbage collected if no other references exist, 3) This behavior is crucial for memory management and preventing memory leaks, 4) Regular Maps maintain strong references that prevent garbage collection, 5) WeakMap's references don't interfere with garbage collection of key objects, 6) This makes WeakMap ideal for associating metadata with objects without preventing their cleanup, 7) The weakness applies only to the keys, not the values, 8) This behavior is fundamental to WeakMap's role in memory-conscious programming.