Rest parameter enables you to signify an ‘infinite’ parameter to a function.
...
serves two purposes in Javascript -
- Spread operator - know what spread operators can do
- Rest parameter for a function
Rest parameter just tells Javscript that there can be zero or infinite parameters for the function. The elements are available as an array within the function.
|
|
Or, you could do partial parameters..
|
|
You can see similarities between ‘rest’ and ‘spread’, don’t you? While ‘spread’ expands elements of an object, ‘rest’ collects elements in parameter of a function as an array.
My current favourite pattern for passing arguments to functions is to get them all in one beautiful object. The receiving function just refers to whatever variables it is interested in and leaves the rest alone.