// Gather the remaining parameters into an array
// rest params must be at the end
const func = (a, b, ...args) => {
console.log(args); // [4, 6, 7]
var newArgs = args.reduce((arg, currVal) => {
return arg * currVal;
})
return newArgs;
}
func(1, 2, 4, 6, 7); // 168
// arguments object
// Gives us the number of arguments passed in the function
// Looks like an array, but not actually an array
// the prototype is an object
// It's a list with one mthod on it, .length
// However, you can iterate over it with a 'for of' loop because it has a 'symbol.iterator'
// Does not support array methods
// arrow functions do not have 'arguments'
function addUpNumbers() {
let total = 0;
for (const num of arguments) {
console.log(arguments.length);
total += num;
}
console.log(total);
return total;
}
addUpNumbers(10,23,52,34,12,13,123);