Export (0) Print
Expand All

length Property (Function) (JavaScript)

Returns the number of arguments defined for a function.

functionName.length

The required functionName is the name of the function.

The length property of a function is initialized by the scripting engine to the number of arguments in the function's definition when an instance of the function is created.

What happens when a function is called with a number of arguments different from the value of its length property depends on the function.

The following example illustrates the use of the length property:

function ArgTest(a, b){
   var s = "";

   s += "Expected Arguments: " + ArgTest.length;
   s += "<br />";
   s += "Passed Arguments: " + arguments.length;

   document.write (s);
}

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Applies To: Function Object (JavaScript)

Community Additions

Show:
© 2014 Microsoft