1// For arrow functions, rest parameters should be preferred.
2let functionExpression = (...args) => {
3 console.log("Arguments", args)
4};
1function sum(...values) {
2 console.log(values);
3}
4sum(1);
5sum(1, 2);
6sum(1, 2, 3);
7sum(1, 2, 3, 4);
8
9
10function sum(...values) {
11 let sum = 0;
12 for (let i = 0; i < values.length; i++) {
13 sum += values[i];
14 }
15
16 return sum;
17}
18console.log(sum(1)); //1
19console.log(sum(1, 2)); //3
20console.log(sum(1, 2, 3)); // 5
21console.log(sum(1, 2, 3, 4)); //10