0

I was trying to get the length of a named function using the arguments.length:

var a = function(b,c){
console.log(arguments.length);
};
a(1,2); //2 (this is what I'm expecting)


(function(b,c){
console.log(arguments.length);
})(1,2); //it returns 2 also


(b,c) => {
console.log(arguments.length);
};
(1,2); //2 also

but when I tried to use named arrow function:

let a = (b,c) => {
console.log(arguments.length);
};
a(1,2); //ReferenceError: arguments is not defined

and this:

((b,c) => {
console.log(arguments.length);
})(1,2); //ReferenceError: arguments is not defined

I'm really confused now

soyjean
  • 3
  • 3

1 Answers1

1

Arrow functions do not bind the arguments magic variable. Your first test is simply wrong; the return value of the expression (1,2) is 2, but only because 2 is the last operand to the , operator, not because of arguments.length. The "anonymous arrow function" isn't even being invoked in that sample.

deceze
  • 471,072
  • 76
  • 664
  • 811