javascript
Spread & Rest Operators in JavascriptjavascriptLevel1
Progress0%
Contents
Spread & Rest Operators in Javascript
1 / 8
Introduction
Spread & Rest Operators
Both the spread and rest operators use the same syntax — three dots (...) — but they do opposite things depending on where they are used.
| Operator | Where used | What it does |
|---|---|---|
Spread (...) | Where values are expected | Expands an iterable into individual elements |
Rest (...) | Where parameters are defined | Collects multiple elements into a single array |
A simple way to remember:
- Spread — takes one thing and spreads it into many.
- Rest — takes many things and collects them into one.