JavaScript » Functions » arguments.length


The arguments.length property returns the number of arguments passed to a function, as opposed to the function.length property, which returns the number of arguments that a function expects to receive.

The distinction between the arguments.length and Function.length properties is demonstrated in this next example of a function which is designed to take as its arguments 3 numbers and then calculate the average of them. If exactly 3 arguments are passed to it, it carries out the calculation, otherwise it returns an appropriate message.


function calc3Average(x, y, z)
if(arguments.length != calc3Average.length)
return "Use 3 arguments!"
var average = (x + y + z)/3
return "The average is " + average