The length property indicates the number of parameters expected by the function.

Property attributes of Function.length
Writable no
Enumerable no
Configurable yes


length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number excludes the rest parameter and only includes parameters before the first one with a default value. By contrast, arguments.length is local to a function and provides the number of arguments actually passed to the function.

Data property of the Function constructor

The Function constructor is itself a Function object. Its length data property has a value of 1. The property attributes are: Writable: false, Enumerable: false, Configurable: true.

Property of the Function prototype object

The length property of the Function prototype object has a value of 0.


Using function length

console.log(Function.length); /* 1 */

console.log((function()        {}).length); /* 0 */
console.log((function(a)       {}).length); /* 1 */
console.log((function(a, b)    {}).length); /* 2 etc. */

console.log((function(...args) {}).length); 
// 0, rest parameter is not counted

console.log((function(a, b = 1, c) {}).length);
// 1, only parameters before the first one with 
// a default value is counted


Browser compatibilityUpdate compatibility data on GitHub

Chrome Edge Firefox Internet Explorer Opera Safari
length 1 12 1 4 3 1
Configurable: true 43 12 37 No 30 10
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
length 1 18 4 10.1 1 1.0
Configurable: true 43 43 37 30 10 4.0
length Yes
Configurable: true Yes

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.