Function: length
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thelength data property of aFunction instance indicates the number of parameters expected by the function.
In this article
Try it
function func1() {}function func2(a, b) {}console.log(func1.length);// Expected output: 0console.log(func2.length);// Expected output: 2Value
A number.
Property attributes ofFunction: length | |
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
Description
AFunction object'slength property indicates how many arguments the function expects, i.e., the number of formal parameters:
- Only parameters before the first one with adefault value are counted.
- Adestructuring pattern counts as a single parameter.
- Therest parameter is excluded.
By contrast,arguments.length is local to a function and provides the number of arguments actually passed to the function.
TheFunction constructor is itself aFunction object. Itslength data property has a value of1.
Due to historical reasons,Function.prototype is a callable itself. Thelength property ofFunction.prototype has a value of0.
Examples
>Using function length
js
console.log(Function.length); // 1console.log((() => {}).length); // 0console.log(((a) => {}).length); // 1console.log(((a, b) => {}).length); // 2 etc.console.log(((...args) => {}).length);// 0, rest parameter is not countedconsole.log(((a, b = 1, c) => {}).length);// 1, only parameters before the first one with// a default value are countedconsole.log((({ a, b }, [c, d]) => {}).length);// 2, destructuring patterns each count as// a single parameterSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-function-instances-length> |