Rest Parameter | JavaScript

Rest Parameter
Rest parameter a modern feature of JavaScript that allows a function to store multiple arguments in a single array. It is an improved way of handling function parameter. Rest parameter is added in ES2015 or ES6 which improved the ability to handle parameter.
“
function name[...param] //... is the rest parameter
{
// statement;
}
”
Let’s see how it works:

Function without rest parameter; no error will be thrown even when arguments passed are more than the parameters, but only the first two arguments will be evaluated.

But, while using rest parameter, it’s a different case. With the use of the rest parameter, we can gather any number of arguments into an array and perform any action with them.
Also, the rest parameter must be the last parameter in the list because a Comma is not permitted after the rest element.

I hope this helps someone
Stay tuned
Comments
Join the discussionNo comments yet. Be the first to comment.




