Using the Rest Parameter
Learn how the rest parameter addresses the issues with arguments and makes the code more concise.
We'll cover the following...
We'll cover the following...
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
Arraytype.
The rest parameter in action
Let’s convert the max() function from the previous example to use a rest ...