WeakMap & WeakSet
What is a limitation of using WeakMap for caching computed values?
The key limitation of WeakMap for caching is: 1) It cannot use primitive values as keys, only objects, 2) This restricts its use for caching based on primitive values like strings or numbers, 3) Primitive-based caching must use regular Map or other structures, 4) This limitation comes from WeakMap's fundamental design for object references, 5) It affects common caching scenarios where primitive keys are natural, 6) Workarounds like object wrappers add complexity and overhead, 7) This constraint is part of WeakMap's focus on object-based weak references, 8) Understanding this limitation is crucial for choosing appropriate caching strategies.