The length property of the JavaScript function

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.