What is the spread operator in JavaScript?
Answer
The spread operator (..., ES6) expands an iterable (array, string, or object with ES2018) into individual elements. Arrays: copy — const copy = [...arr]; merge — const merged = [...arr1, ...arr2]; pass array as function arguments — Math.max(...numbers). Objects: copy — const copy = {...obj}; merge/override — const updated = {...defaults, ...overrides}. String to array of characters: [..."hello"] → ["h","e","l","l","o"]. The spread operator creates shallow copies — nested objects are still referenced, not deep-copied. Do not confuse with the rest parameter (function fn(...args)) which collects remaining arguments into an array. Spread is used in contexts where multiple items are expected; rest is used in function parameter lists to capture remaining arguments.