Rest and Spread
The spread operator ... expands iterables. The rest parameter collects remaining arguments into an array.
The spread operator ... expands iterables. The rest parameter collects remaining arguments into an array.
function sum(...nums) { return nums.reduce((a, b) => a + b, 0); }
sum(1, 2, 3, 4); // 10
const arr1 = [1, 2]; const arr2 = [3, 4];
const merged = [...arr1, ...arr2]; // [1,2,3,4]
const obj = { a: 1 }; const clone = { ...obj, b: 2 }; // { a:1, b:2 }
Math.max(...[5, 3, 9]); // 9
Spread creates a shallow copy — nested objects are still references.
More in JavaScript