Baseline Widely available
The arguments.length
data property contains the number of arguments passed to the function.
A non-negative integer.
Writable yes Enumerable no Configurable yes DescriptionThe arguments.length
property provides the number of arguments actually passed to a function. This can be more or less than the defined parameter's count (see Function.prototype.length
). For example, for the function below:
function func1(a, b, c) {
console.log(arguments.length);
}
func1.length
returns 3
, because func1
declares three formal parameters. However, func1(1, 2, 3, 4, 5)
logs 5
, because func1
was called with five arguments. Similarly, func1(1)
logs 1
, because func1
was called with one argument.
In this example, we define a function that can add two or more numbers together.
function adder(base /*, num1, â¦, numN */) {
base = Number(base);
for (let i = 1; i < arguments.length; i++) {
base += Number(arguments[i]);
}
return base;
}
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4