--- title: Use the Rest Parameter with Function Parameters --- # Use the Rest Parameter with Function Parameters #### Relevant LInks - [Rest parameter explanation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters "Mozilla Developer Network") - [Spread operator compared to rest parameter](https://stackoverflow.com/questions/33898512/spread-operator-vs-rest-parameter-in-es2015-es6 "Stack Overflow") - Image of youtube video link spread and rest parameter Video explaining spread and rest ### Example This code ```javascript const product = (function() { "use strict"; return function product(n1, n2, n3) { const args = [n1, n2, n3]; return args.reduce((a, b) => a * b, 1); }; })(); console.log(product(2, 4, 6)); //48 ``` Can be written as such ```javascript const product = (function() { "use strict"; return function product(...n) { return n.reduce((a, b) => a * b, 1); }; })(); console.log(product(2, 4, 6)); //48 ```