I'm wondering why the following arrow function, named 'countArg2' doesn't work. Is there anybody can explain what's wrong please?
function countArg1() {
return arguments.length;
}
countArg1(1, 2, 3); //3
const countArg2 = () => arguments.length;
countArg2(1, 2, 3);
// Uncaught ReferenceError: arguments is not defined
Thank you in advance.
You have to parse the arguments to the arrow function like this
const countArg2 = (...arguments) => arguments.length;
console.log(countArg2(1, 2, 3));
// VM6745:1 Uncaught ReferenceError: arguments is not defined
// at mArgs (<anonymous>:1:29)
// at <anonymous>:2:1