Core Collections: Map, Set, WeakMap & Object Destructuring
1Concept
Map allows keys of ANY type (including objects and functions) and preserves insertion order. Set stores unique values. Object/Array destructuring and spread syntax (...) simplify data manipulation.
2Architecture Diagram
Map: Any key type (objects, functions) | O(1) Lookup Set: Unique values collection | O(1) Has Check
3Code Example
Stage 0 Language Foundations
const userMap = new Map();
const keyObj = { role: "admin" };
userMap.set(keyObj, "Superuser Privileges");
console.log(`Map lookup with object key: ${userMap.get(keyObj)}`);
// Destructuring & Rest
const candidate = { name: "Alex", stack: "Full Stack", exp: 5 };
const { name, ...rest } = candidate;
console.log(`Name: ${name}, Other Details:`, JSON.stringify(rest));4Expected Output
Map lookup with object key: Superuser Privileges
Name: Alex, Other Details: {"stack":"Full Stack","exp":5}5Key Takeaways
- ✓Prefer Map over plain Object for dynamic key-value caches with frequent additions/removals.
- ✓Set eliminates array duplicates instantly (new Set(array)).
- ✓Spread syntax creates shallow copies.