The rest parameter
The rest parameter is also represented by the "…
" token. The last parameter of a function prefixed with "…
" is called as a rest parameter. The rest parameter is an array type, which contains the rest of the parameters of a function when number of arguments exceeds the number of named parameters.
The rest parameter is used to capture a variable number of the function arguments from within a function.
Before ES6, the programmers used the arguments
object of a function to retrieve the extra arguments, passed to the function. The arguments
object is not an array, but it provides some interfaces that are similar to an array.
Here is a code example that shows how to use the arguments
object to retrieve the extra arguments:
function myFunction(a, ...
Get React: Building Modern Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.