Skip to main content
The ... token in JavaScript represents two distinct syntactic features depending on its lexical context: Spread syntax and Rest syntax. Spread syntax expands an iterable or object into individual elements or properties, while Rest syntax condenses multiple discrete elements or properties into a single array or object binding.

Spread Syntax (Expansion)

Spread syntax operates by unpacking values from a source. When applied to iterables (like Arrays, Strings, Maps, or Sets), it invokes the object’s [Symbol.iterator]() method to extract values. When applied to objects, it extracts enumerable own properties. Contexts: Function invocations, array literals, and object literals.
Technical Characteristics:
  • Multiple Usage: The spread operator can be used multiple times within the same expression.
  • Evaluation Order: Elements or properties are evaluated and inserted in the exact order they appear in the literal. Subsequent object properties with the same key will overwrite preceding ones.
  • Shallow Operation: Spread performs a shallow read. Nested objects or arrays are copied by reference, not by value.

Rest Syntax (Condensation)

Rest syntax operates by packing remaining, unassigned values into a newly allocated data structure. It acts as a catch-all for trailing elements during assignment or function execution. Contexts: Function parameter declarations and destructuring assignments.
Technical Characteristics:
  • Terminal Position: A rest element or parameter must be the final entry in its destructuring pattern or parameter list. Placing a comma or another variable after a rest element throws a SyntaxError. However, in array destructuring and function parameters, this final rest element is not restricted to a simple identifier; it can itself be a destructuring pattern (e.g., function f(...[a, b]) {}).
  • Instance Type: In array destructuring and function parameters, the rest binding is always a true Array instance, granting access to Array.prototype methods (unlike the legacy array-like arguments object). In object destructuring, it is a plain Object.
  • Empty States: If there are no remaining elements or properties to collect, the rest binding evaluates to an empty array [] or an empty object {}, rather than undefined.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More