Showing Error "argument is not defined" while adding multiple arguments in arrow function but It's Working in Normal Function call
Solution 1:
This is because arrow functions do not have argument bindings.
option 1 changing arrow function to take an array arguments
parameter
let sum = (arguments) => {
if( arguments.length == 0){
console.log("NO Argument Passed!");
}
else{
let sum1 = 0;
for(let number in arguments){
sum1 += arguments[number];
}
console.log(sum1);
}
};
sum([10,20]);
option 2 rest parameters which allows indefinite amount of arguments
let sum = (...arguments) => {
if( arguments.length == 0){
console.log("NO Argument Passed!");
}
else{
let sum1 = 0;
for(let number in arguments){
sum1 += arguments[number];
}
console.log(sum1);
}
};
sum(10,20);