Using the Rest Parameter
Learn how the rest parameter addresses the issues with arguments and makes the code more concise.
A rest parameter is defined using ellipsis (...
) to signify that that parameter is a placeholder for any number of arguments.
How the rest parameter is better than arguments
The rest parameter directly addresses the issues with arguments
.
- First, it stands for the rest of the parameters and is highly visible in the parameter list.
- Second, the rest parameter is of
Array
type.
The rest parameter in action
Let’s convert the max()
function from the previous example to use a rest parameter.
Get hands-on with 1400+ tech skills courses.