As described in other answers, the length property reports this. So zero.length will be 0, one.length will be 1, and two.length will be 2.
As in ES2015, we have two wrinkles:
- Functions can have a βrestβ parameter at the end of the parameter list, which collects any arguments given at or after this position into a real array (as opposed to the
arguments pseudo-array) - Function parameters may have default values.
The "rest" parameter is not taken into account when determining the arity of a function:
function stillOne(a, ...rest) { } console.log(stillOne.length);
Similarly, a parameter with a default argument does not add to arity and actually prevents any others following it from adding to it, even if they do not have explicit default values ββ(it is assumed that they have a default value of undefined ):
function oneAgain(a, b = 42) { } console.log(oneAgain.length);
TJ Crowder Dec 15 '16 at 18:57 2016-12-15 18:57
source share