Destructuring & Spread Operator
What is the spread operator in JavaScript?
The spread operator (`...`) in JavaScript is a syntax that expands iterables (like arrays, strings, or objects) into individual elements. For arrays, it spreads the array into individual elements. For example, `Math.max(...[1, 2, 3])` is equivalent to `Math.max(1, 2, 3)`. For objects, it copies enumerable properties from one object to another. For example, `{...obj1, ...obj2}` creates a new object with properties from both obj1 and obj2. The spread operator was introduced in ES6 for arrays and expanded to objects in ES2018. It's commonly used for creating copies of arrays or objects, combining multiple arrays or objects, passing array elements as function arguments, and converting iterables like NodeLists to arrays. Unlike the rest parameter (which also uses `...` syntax), the spread operator is used in function calls or array/object literals rather than in declarations.