Rest Parameters
Multiple Choice Easy
Question
What does function f(...args) { return args; } give for f(1,2,3)?
Hint
Rest params collect all arguments into an array.
Explanation
The rest parameter ...args collects all passed arguments into an array. f(1,2,3) returns [1, 2, 3]. This replaces the old arguments object which was array-like but not a true array. Rest parameters must be the last parameter in a function. They are useful for variadic functions.
Related Resources
Related Lessons
- Functions
Learn JS functions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.