Home > Web Front-end > JS Tutorial > Learning arguments in Javascript

Learning arguments in Javascript

高洛峰
Release: 2016-12-13 17:55:57
Original
1314 people have browsed it

arguments is a parameter of the currently executing function, which saves the parameters of the current call of the function.

Usage: function.arguments[i].

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

arguments cannot be created. They are parameters of the function itself and can only be used when the function starts executing.

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

Below, use an example to demonstrate:

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

You can see that this is a pop-up in the browser window, and the argument type is object. The pop-up result is 4.

The following is the callee method, which returns the function object being executed. Learning arguments in Javascript

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

Pop-up result:

Learning arguments in Javascript

The following is the key, what is the value returned by arguments.callee.length?

function argumentsTest (a,b) {
        // alert(typeof arguments);
        // alert(arguments.length);
        alert(arguments[1]);
}
argumentsTest(1,2);
Copy after login
The pop-up result:

Learning arguments in Javascript

It can be seen that arguments.length returns the length of the actual parameter, which is 4; and arguments.callee.length returns the length of the formal parameter, which is only 2.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template