Day 2: Spread & Rest Operators
Daily Objective
Section titled “Daily Objective”Master the ... syntax as both a spread operator (expansion) and rest operator (collection).
1. Spread (Expansion) & Rest (Collection)
Section titled “1. Spread (Expansion) & Rest (Collection)”// Spread: Shallow copy and mergingconst 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 argumentsfunction sumAll(...numbers) { return numbers.reduce((acc, n) => acc + n, 0);}Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Clone an object and overwrite one property using object spread.
- Write a function that accepts any number of arguments and returns their product using rest.