Syntaxfunction fn(...args) {}
Examplefunction sum(...numbers) {
return numbers.reduce((total, n) => total + n, 0);
}
console.log(sum(5, 10, 15));
Output30
Note Rest must be the last parameter. Unlike the old arguments object, rest gives you a real Array with all array methods.
Rest Parameters in Functions
JS · Functions Syntaxfunction fn(first, ...rest) {}
Examplefunction logTagged(level, ...messages) {
const timestamp = new Date().toISOString();
console.log(`[${level}] ${timestamp}:`, ...messages);
}
logTagged("INFO", "Server started", "on port 3000");
Output[INFO] 2026-04-04T...: Server started on port 3000
Note Rest parameters collect remaining arguments into a real Array. Unlike arguments, they work in arrow functions too.