This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

length

Summary

Gets the number of arguments defined for a function.

Syntax

functionName.length

Examples

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;

     return s;
 }

 document.write(ArgTest(1, 2));

 // Output:
 // Expected Arguments: 2
 // Passed Arguments: 2

Remarks

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.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article