- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Rest Parameters
JavaScript Functions
JavaScript Rest Parameters
JavaScript rest parameters collect any number of arguments into a single array.
A rest parameter is written with three dots before the name.
It lets one function accept two arguments, or ten, without changing the definition.
Example
Example
javascript
function addAll(...numbers) {
let total = 0;
for (const n of numbers) {
total += n;
}
return total;
}
console.log(addAll(1, 2, 3, 4));