Length can get 3, "123". Length can also get 3, this slightly understand JS know.
But Eval. Length, RegExp. Length, "". ToString. Length, 1..toString. What does length get?
Get 1, 2, 0, 1, respectively, what do these numbers represent?
In fact, the length of the function gets the number of formal parameters.
Let's take a quick look at an example:
function Test(a,b,c) {}test. length //3function Test(a,b,c,d) {}test. length //4
is not very simple, but there is also a special, if the function is called through the arguments parameters, without actually defining the parameters, length will only get 0.
function Test() {console.log ( arguments );} Test. length //0
This function can actually pass in the parameter, and the parameter is called internally, but length does not know the number of arguments passed in.
You can only pass arguments when the function is executed. Length gets the number of arguments.
function Test() {console.log ( arguments. Length );} Test (1,2,3);//Output 3Test1,2,3,4);//Output 4
So the length property of a function can only get the number of its parameters, but not the number of arguments .
The length property of the JavaScript function