mozilla
Your Search Results

    length

    Summary

    The length property specifies the number of arguments expected by the function.

    Property attributes of 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 does not include the rest parameter. 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

    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 */
    

    Specifications

    Specification Status Comment
    ECMAScript 1st Edition. Standard Initial definition. Implemented in JavaScript 1.1.
    length property of the Function constructor:
    ECMAScript 5.1 (ECMA-262)
    The definition of 'Function.length' in that specification.

    length property of the Function prototype object:
    ECMAScript 5.1 (ECMA-262)
    The definition of 'Function.length' in that specification.

    length property of Function instances:
    ECMAScript 5.1 (ECMA-262)
    The definition of 'Function.length' in that specification.
    Standard  
    length property of the Function constructor:
    ECMAScript 6 (ECMA-262)
    The definition of 'Function.length' in that specification.

    length property of the Function prototype object:
    ECMAScript 6 (ECMA-262)
    The definition of 'Function.length' in that specification.

    length property of Function instances:
    ECMAScript 6 (ECMA-262)
    The definition of 'Function.length' in that specification.
    Release Candidate The configurable attribute of this property is now true.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
    Configurable: true ? 37 (37) ? ? ?
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
    Configurable: true ? ? 37.0 (37) ? ? ?

    See also

    Document Tags and Contributors

    Contributors to this page: Sevenspade
    Last updated by: Sevenspade,