arguments.length

  • Revision slug: JavaScript/Reference/Functions_and_function_scope/arguments/length
  • Revision title: length
  • Revision id: 74929
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment no changes

Revision Content

Summary

Specifies the number of arguments passed to the function.

Property of arguments
Implemented in JavaScript 1.1
ECMAScript Edition ECMA-262

Description

arguments.length provides the number of arguments actually passed to a function. By contrast, the Function.length property indicates how many arguments a function expects.

Examples

Example: Using Function.length and arguments.length

The following example demonstrates the use of Function.length and arguments.length.

function addNumbers(x,y){
   if (arguments.length == addNumbers.length) {
      return (x+y)
   }
   else return 0
}

If you pass more than two arguments to this function, the function returns 0:

result=addNumbers(3,4,5)   // returns 0
result=addNumbers(3,4)     // returns 7
result=addNumbers(103,104) // returns 207

See also

Function.length

{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Fonctions/arguments/length", "ja": "ja/Core_JavaScript_1.5_Reference/Functions/arguments/length", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Funkcje/arguments/length" } ) }}

Revision Source

<h2 name="Summary">Summary</h2>
<p>Specifies the number of arguments passed to the function.</p>
<table class="standard-table"> <tbody> <tr> <td class="header" colspan="2">Property of <a href="/en/JavaScript/Reference/Functions_and_function_scope/arguments" title="en/JavaScript/Reference/Functions_and_function_scope/arguments">arguments</a></td> </tr> <tr> <td>Implemented in</td> <td>JavaScript 1.1</td> </tr> <tr> <td>ECMAScript Edition</td> <td>ECMA-262</td> </tr> </tbody>
</table><h2 name="Description">Description</h2>
<p>arguments.length provides the number of arguments actually passed to a function. By contrast, the Function.length property indicates how many arguments a function expects.</p>
<h2 name="Examples">Examples</h2>
<h3 name="Example:_Using_Function.length_and_arguments.length">Example: Using <code>Function.length</code> and <code>arguments.length</code></h3>
<p>The following example demonstrates the use of <code>Function.length</code> and <code>arguments.length</code>.</p>
<pre>function addNumbers(x,y){
   if (arguments.length == addNumbers.length) {
      return (x+y)
   }
   else return 0
}
</pre>
<p>If you pass more than two arguments to this function, the function returns 0:</p>
<pre>result=addNumbers(3,4,5)   // returns 0
result=addNumbers(3,4)     // returns 7
result=addNumbers(103,104) // returns 207
</pre>
<h2 name="See_also">See also</h2>
<p><a href="/en/JavaScript/Reference/Global_Objects/Function/length" title="en/JavaScript/Reference/Global_Objects/Function/length">Function.length</a></p>
{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Fonctions/arguments/length", "ja": "ja/Core_JavaScript_1.5_Reference/Functions/arguments/length", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Funkcje/arguments/length" } ) }}
Revert to this revision