JavaScript » Functions » arguments.length

Syntax:
[Function.]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.

Examples

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