1// With Rest Parameter
2let sum = (...nums) => {
3 let total = 0;
4 for (let num of nums) {
5 total += num;
6 }
7 return total;
8};
9console.log(sum(4, 23, 65, 2)); // 94
10
11
12// Before
13function sum() {
14 let total = 0;
15 for (let argument of arguments) {
16 total += argument;
17 }
18 return total;
19}
20console.log(sum(4, 23, 65, 2)); // 94
1var sum = 0;
2function addAll(){
3 for (var i = 0; i<arguments.length; i++){
4 sum+=arguments[i];
5 }
6 console.log(sum);
7}
8
9addAll(1, 2, 3, 4, 5, 6, 7, 8, 9,10); //we can provide inifite numbers as argument