Suggested answer

Both use the ... syntax but in opposite directions. Spread: Expands an iterable (array, string, object) into individual elements. Array spread: const merged = [...arr1, ...arr2]; — shallow copy and merge. Object spread: const updated = { ...original, name: 'New' }; — immutable update pattern (later keys overwrite earlier). Function call: Math.max(...numbers);. Rest: Collects multiple arguments into an array. Function parameters: function sum(...nums) { return nums.reduce((a, b) => a + b, 0); }. Destructuring rest: const [first, ...remaining] = arr;. Key distinction: spread is used where values are consumed (right-hand side, function arguments); rest is used where values are collected (parameter lists, destructuring left-hand side).

Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.

Community comments (0)

No comments yet.

Sign in or create a free account to add a comment. Comments are moderated before they appear.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.