Using the Rest Parameter

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 1200+ tech skills courses.