As is covered in other answers, the length property tells you that. So zero.length will be 0, one.length will be 1, and two.length will be 2.
As of ES2015, we have two wrinkles:
- Functions can have a "rest" parameter at the end of the parameter list which gathers up any arguments given at that position or afterward into a true array (unlike the
arguments pseudo-array)
- Function parameters can have default values
The "rest" parameter isn't counted when determining the arity of the function:
function stillOne(a, ...rest) { }
console.log(stillOne.length); // 1
Similarly, a parameter with a default argument doesn't add to the arity, and in fact prevents any others following it from adding to it even if they don't have explicit defaults (they're assumed to have a silent default of undefined):
function oneAgain(a, b = 42) { }
console.log(oneAgain.length); // 1
function oneYetAgain(a, b = 42, c) { }
console.log(oneYetAgain.length); // 1