Web/JavaScript/Reference/Global objects/Function/length
The length property indicates the number of parameters expected by the function.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Property attributes of Function.length
|
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
Description
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.
Examples
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
Specifications
| Specification |
|---|
| ECMAScript (ECMA-262)The definition of 'Function.length' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 4 |
Opera
Full support 3 |
Safari
Full support 1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
nodejs
Full support Yes |
| Configurable: true | Chrome
Full support 43 |
Edge
Full support 12 |
Firefox
Full support 37 |
IE
No support No |
Opera
Full support 30 |
Safari
Full support 10 |
WebView Android
Full support 43 |
Chrome Android
Full support 43 |
Firefox Android
Full support 37 |
Opera Android
Full support 30 |
Safari iOS
Full support 10 |
Samsung Internet Android
Full support 4.0 |
nodejs
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
See also
Function.length by Mozilla Contributors is licensed under CC-BY-SA 2.5.