Learning about arguments in Javascript

Source: Internet
Author: User
Arguments is a parameter of the function currently being executed. It stores the parameters currently called by the function. Arguments is a parameter of the function currently being executed. It stores the parameters currently called by the function.

Usage: function. arguments [I].

Function is optional and the name of the function currently being executed.

Arguments cannot be created. It is a function parameter and can only be used when the function is executed.

Although the use of arguments is similar to an array, it is not an array.

The following is an example:

function argumentsTest (a,b) {        alert(typeof arguments);}argumentsTest(1,2);

As you can see, this is displayed in the browser window. The arguments type is object.

function argumentsTest (a,b) {        // alert(typeof arguments);        alert(arguments.length);}argumentsTest(1,2);

Pop-up results:

function argumentsTest (a,b) {        // alert(typeof arguments);        // alert(arguments.length);        alert(arguments[1]);}argumentsTest(1,2);

Pop-up results:

Note the following code:

function argumentsTest (a,b) {    // alert(typeof arguments);    alert(arguments.length);    // alert(arguments[1]);}argumentsTest(1,2,3,4);

Pop-up results:

The pop-up result is 4.

The following is the function object that is being executed in the callee method.

function argumentsTest (a,b) {    // alert(typeof arguments);    // alert(arguments.length);    // alert(arguments[1]);    alert(arguments.callee);    // alert(arguments.callee.length);}argumentsTest(1,2,3,4);

Pop-up results:

The following is the key. What is returned by arguments. callee. length?

function argumentsTest (a,b) {    // alert(typeof arguments);    // alert(arguments.length);    // alert(arguments[1]);    //alert(arguments.callee);    alert(arguments.callee.length);}argumentsTest(1,2,3,4);

Pop-up results:

It can be seen that arguments. length returns the length of the real parameter, which is 4; while arguments. callee. length returns the length of the form parameter, which is only 2.

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.