What are rest parameters?
By FrontendPro Editorial Team Updated 9/26/2026
Answer
Rest parameters collect any remaining arguments into a real array, written with three dots before the parameter name.
function sum(...numbers) {
return numbers.reduce((a, b) => a + b, 0);
}
sum(1, 2, 3); // 6
sum(); // 0 — an empty array, not undefined
They can follow named parameters, and must come last:
function log(level, ...messages) { /* ... */ }
log("warn", "disk", "almost", "full"); // level="warn", messages=[...]
Only one rest parameter is allowed, and nothing may follow it — the syntax is a syntax error otherwise.
Why not arguments
The old arguments object is array-like: it has length and indices but none of the array methods, so you had to convert it before doing anything useful. Rest parameters are a genuine array from the start.
arguments also does not exist in arrow functions, and it includes every argument rather than just the extra ones. There is no reason to use it in new code.
Rest versus spread
Same three dots, opposite direction. Rest collects and appears in a parameter list or on the left of a destructuring. Spread expands and appears at a call site or inside a literal:
function f(...args) {} // rest — gathers
f(...[1, 2, 3]); // spread — scatters
In destructuring
const [first, ...others] = [1, 2, 3]; // others = [2, 3]
const { id, ...withoutId } = { id: 1, a: 2, b: 3 }; // withoutId = { a: 2, b: 3 }
The object form is the idiomatic way to remove a key without mutating — common when stripping an internal field before sending data to an API.
One detail: a rest parameter is not counted in fn.length, so a generic curry helper relying on arity will not work with it.
