Length attribute of JavaScript function
[123, 3]. length can get 3, "". length can also get 3, which is known for js.
But what does eval. length, RegExp. length, "". toString. length, 1... toString. length get?
What do the numbers 1, 2, 0, and 1 represent?
In fact, the length of the function gets the number of parameters.
Let's take a simple example:
Function test (a, B, c) {} test. length // 3 function test (a, B, c, d) {} test. length // 4
It is not very simple, but it is also special. If the function calls the parameter through arguments, but does not actually define the parameter, the length will only get 0.
Function test () {console. log (arguments);} test. length // 0
This function can indeed pass in parameters, and also call the parameters internally, but length cannot know the number of input parameters.
The number of real parameters can only be obtained through arguments. length during function execution.
Function test () {console. log (arguments. length);} test (, 3); // output 3 test (,); // output 4
Therefore, the length attribute of the function can only obtain itsParametersNumber, but cannot knowReal ParametersNumber.