Rest parameters :
Syntax: ...parameter
function addition (num1, num2, ...num){
var sum = num1+num2;
for ( var v of num){
sum = sum + v ;
}
console.log(sum);
}
addition(1,2,3 ) \\\\first 2 arguments are reserved and remaining reserved for rest variable..
addition(1,2,3 ,5)
addition(1,2,3 5,7)
Note : Every function contains a default object, which is called an argument; you can use it. It stores the arguments. Accessing a specific element through an index: Arguments [0] Length: it returns the length of objects. Ex: console.log(arguments);
function dis(para1, ...rest, para3 ){ } // error.
function dis(para1, para3, ...rest){ } // ok
Spread operator :
arra = [10,55,43,26];
console.log(...arra) //10 55 43 26
Example _2 :
var name = "Shivaji";
console.log(name); // without spread operator
console.log(...name); // with spread operator
//Output :
Shivaji
S h i v a j i