With a WeakMap, we can attach data without mutating obj. This kind of non-mutating attaching has two main use cases.
The WeakMap holds the key weakly: If the key is garbage-collected, the whole entry is removed, and the data can be garbage-collected, too.
Objects and symbols which are not registered (created via Symbol.for()) can be keys in WeakMaps. Symbols are compared by identity, not value.
Registered symbols are never garbage-collected, which would cause memory leaks if used as WeakMap keys. Symbols as WeakMap keys solve important issues.
Collection
[
|
...
]