Destructuring & Spread Operator
What is the difference between the spread operator and the rest parameter in JavaScript?
The key difference is that the spread operator expands elements, while the rest parameter collects them into an array. Though they both use the same `...` syntax, they serve opposite purposes. The spread operator is used in function calls, array literals, or object literals to expand elements from an iterable (like an array) or properties from an object. For example: `fn(...array)` or `[1, 2, ...array]`. The rest parameter is used in function parameters or destructuring assignments to collect multiple elements into a single array. For example: `function fn(...args) {}` or `const [first, ...others] = array;`. You can think of spread as unpacking a collection, while rest is packing multiple items into a collection. Both were introduced in ES6, but with different purposes and in different contexts. The ability to spread was extended to objects in ES2018.