[1,2,3].length can get 3, "123". Length can also get 3, this slightly understand JS all know.
But Eval.length,regexp.length, "". tostring.length,1. What will tostring.length get?
Get 1,2,0,1, what do these numbers mean?
This is a group of new friends have been asked a question, in fact, the length of the function is the number of parameters.
Let's take a quick look at an example:
Copy Code code as follows:
function test (a,b,c) {}
Test.length//3
function test (a,b,c,d) {}
Test.length//4
is not very simple, but there are special, if the function inside is through arguments call parameters, without the actual definition of parameters, length will only get 0.
Copy Code code as follows:
function test () {console.log (arguments);}
Test.length//0
This function can indeed pass in arguments, and internal parameters are called, but length does not know the number of arguments passed in.
The number of arguments can only be obtained by arguments.length when the function is executed.
Copy Code code as follows:
function test () {console.log (arguments.length);}
Test (1,2,3); Output 3
Test (1,2,3,4); Output 4
So the length property of a function can only get the number of his parameters, but not the number of arguments.