Spread (...) vs Rest (...) Operator
Same syntax (...), completely different purposes. Spread expands elements, Rest collects them.
| Feature | Spread (...) | Rest (...) |
|---|---|---|
| Context | Array literals, object literals, function calls | Function parameters, destructuring |
| Purpose | Expand/unpack elements | Collect remaining elements |
| Position | Anywhere in array/object | Must be last parameter |
| Use case | Copying, merging, passing arguments | Variadic functions, extracting remaining items |
| Direction | One to many | Many to one |
Verdict
Spread expands an iterable into individual elements (used in calls and literals). Rest collects multiple elements into an array (used in function params and destructuring).
Code Example
Related Tutorials
Related Glossary Terms
A syntax for extracting values from arrays or properties from objects into distinct variables. Destructuring simplifies code and is commonly used in function parameters, imports, and React hooks.
Spread OperatorThe ... syntax that expands an iterable (array, string, object) into individual elements. Used for copying arrays/objects, merging, and passing multiple arguments to functions.
Rest ParametersThe ... syntax used in function parameters to collect all remaining arguments into an array. Unlike the arguments object, rest parameters produce a real array.