Chapter VII · Objects
Spread Syntax
Spread syntax (...) expands an object's properties into a new object collection context.
01 How It Works
Think of spreading contents out onto a workbench to combine with new tools.
Spread copies enumerable properties shallowly into new target structures.
example.js
const base = { a: 1, b: 2 };
const extended = { ...base, c: 3 };
1. Target an existing source object.
2. Prepend three dots (...) inside a new object literal.
3. Add additional properties.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const defaults = { mode: "eco", speed: 50 };
const custom = { ...defaults, speed: 80 };
Key Takeaway
Spread syntax simplifies cloning and merging objects immutably.