Parameterx,y : parameter of function
….Args: The rest parameter to pass any number of arguments to the function.
Important Note
It creates a standard array of user-supplied values
.The only last parameter can be the rest parameter. It can not use with function parameters if it is not the last parameter.
Use of Rest Parameter
function fnrest(x, y, ...restarg)
{
console.log(x,y)
console.log(restarg )
}
//calling function
fnrest ("Ja", "va", "rest", "val", "es", "data")
Output of Last Program
Ja va
[ 'rest', 'val', 'es', 'data' ]
The output of
restarg = 'rest', 'val', 'es', 'data' ] that is an array.
Find Length of Rest parameter
To find the length of the rest parameter operator you can use the .length property
Pass Single argument to Rest Parameter
if We pass a single argument to the rest parameter. Even then also it will return an array
Pass No argument to Rest Parameter
if we pass no argument to the rest parameter .Even then also it will return an array