How JavaScript rest parameters actually work

There are two new kinds of parameters: default parameters and rest parameters.

In JavaScript, parameters of functions default to undefined.

Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.

The rest parameter syntax allows representing an  indefinite number of arguments as an array.

* * * 

function multiply(multiplier,  … theArgs) {

return the Args . map(x => multiplier * x);


var arr = multiply(2, 1, 2, 3);

console. log (arr) ; // [2, 4, 6]

Leave a Reply

Your email address will not be published. Required fields are marked *