Rest Parameters in ES6 JavaScript
// Rest Parameters in ES6 JavaScript
// old style
// this is the problem when we have two many parameters
// function sum(a,b,c,d,e,f)
// {
// console.log(a+b+c+d+e+f);
// }
// sum(1,2,3,4,5,6);
// ES6 style
// rest parameter as a array kaunt karke deta hai
function sum(...inputs)
{
console.log(...inputs)
let total = 0;
for(let i of inputs){
total += i;
}
console.log(total);
}
sum(1,2,3,4,5,6,7,8,9);
Comments
Post a Comment