Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

arguments.length Redirect 1

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

Document Tags and Contributors

 Last updated by: Sheppy,