Home > Article > Web Front-end > Learning arguments in Javascript
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);
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.
function argumentsTest (a,b) { // alert(typeof arguments); alert(arguments.length); } argumentsTest(1,2);Pop-up result: 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);The pop-up result: 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.