Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Function: length

BaselineWidely available

Thelength data property of aFunction instance indicates the number of parameters expected by the function.

Try it

function func1() {}function func2(a, b) {}console.log(func1.length);// Expected output: 0console.log(func2.length);// Expected output: 2

Value

A number.

Property attributes ofFunction: length
Writableno
Enumerableno
Configurableyes

Description

AFunction object'slength property indicates how many arguments the function expects, i.e., the number of formal parameters:

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 parameter

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-function-instances-length

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp