Rest parameters are used to Represent Variable Number of arguments. It is equivalent to Varargs in Java. ‘…’ are used to represent variable number of arguments.
HelloWorld.js
function sum(...arr){
var sum = 0;
for(data of arr){
sum += data;
}
return sum;
}
var x = sum(10, 20);
var y = sum(10, 20, 30, 40);
console.log("x : " + x);
console.log("y : " + y);
Output
x : 30
y : 100
Previous Next Home
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here