Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

rest parameters javascript

/*
That allows a function to accept an indefinite number of arguments as an array
*/
function fun(...input){
    let sum = 0;
    for(let i of input){
        sum+=i;
    }
    return sum;
}
console.log(fun(1,2)); //3
console.log(fun(1,2,3)); //6
console.log(fun(1,2,3,4,5)); //15 
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #rest #parameters #javascript
ADD COMMENT
Topic
Name
4+1 =