Putting the rest operator ...
in front of the last formal parameter means that it will receive all remaining actual parameters in an Array.
In the below example, marks would collect the second argument of the function (because the first one is mapped to a) and all the consecutive arguments.
Difference between rest parameters and the arguments object
There are three main differences between rest parameters and the arguments object:
- rest parameters are only the ones that haven't been given a separate name, while the arguments object contains all arguments passed to the function;
- the arguments object is not a real array, while rest parameters are Array instances, meaning methods like sort, map, forEach or pop can be applied on it directly;
- the arguments object has additional functionality specific to itself.
Working with arguments old way
The above code is equivalent to the below ES5 standard code