GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — Function: length - JavaScript | MDN

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.

  • See full compatibility
  • Learn more

The length data property of a Function instance indicates the number of parameters expected by the function.

Try it

function func1() {}

function func2(a, b) {}

console.log(func1.length);
// Expected output: 0

console.log(func2.length);
// Expected output: 2

Value

A number.

Property attributes of Function: length
Writableno
Enumerableno
Configurableyes

Description

A Function object's length property indicates how many arguments the function expects, i.e., the number of formal parameters:

  • Only parameters before the first one with a default value are counted.
  • A destructuring pattern counts as a single parameter.
  • The rest parameter is excluded.

By contrast, arguments.length is local to a function and provides the number of arguments actually passed to the function.

The Function constructor is itself a Function object. Its length data property has a value of 1.

Due to historical reasons, Function.prototype is a callable itself. The length property of Function.prototype has a value of 0.

Examples

Using function length

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

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

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

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

console.log((({ a, b }, [c, d]) => {}).length);
// 2, destructuring patterns each count as
// a single parameter

Specifications

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

Browser compatibility

See also

  • Function

Help improve MDN

Learn how to contribute

This page was last modified on Jul 10, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.