arguments.length

  • Revision slug: JavaScript/Reference/Functions_and_function_scope/arguments/length
  • Revision title: arguments.length
  • Revision id: 346233
  • Created:
  • Creator: hajunge
  • Is current revision? No
  • Comment

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. This can be more or less than the defined parameter count (See Function.length).

Examples

Example: Using arguments.length

In this example we are define a function that can add two or more numbers together.

function adder(base, /*, n2, ... */) {
  base = Number(base);
  for (var i = 0; i < arguments.length; i++) {
    base += Number(arguments[i]);
  }
  return base;
}

See also

Revision Source

<h2 id="Summary" 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-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments" title="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 id="Description" name="Description">Description</h2>
<p>arguments.length provides the number of arguments actually passed to a function. This can be more or less than the defined parameter count (See <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function/length" title="JavaScript/Reference/Global Objects/Function/length">Function.length</a>).</p>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example:_Using_arguments.length" name="Example:_Using_arguments.length">Example: Using <code>arguments.length</code></h3>
<p>In this example we are define a function that can add two or more numbers together.</p>
<pre class="brush: js">
function adder(base, /*, n2, ... */) {
  base = Number(base);
  for (var i = 0; i &lt; arguments.length; i++) {
    base += Number(arguments[i]);
  }
  return base;
}
</pre>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/Function/length" title="JavaScript/Reference/Global_Objects/Function/length">Function.length</a></li>
</ul>
<!--languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Fonctions/arguments/length" } )-->
Revert to this revision