Skip to content

Day 2: Spread & Rest Operators

Master the ... syntax as both a spread operator (expansion) and rest operator (collection).

// Spread: Shallow copy and merging
const base = [1, 2];
const expanded = [...base, 3, 4]; // [1, 2, 3, 4]
const user = { name: 'Alex' };
const updatedUser = { ...user, active: true };
// Rest: Collecting remaining function arguments
function sumAll(...numbers) {
return numbers.reduce((acc, n) => acc + n, 0);
}
  1. Clone an object and overwrite one property using object spread.
  2. Write a function that accepts any number of arguments and returns their product using rest.