Thursday, October 23, 2025
HomeLanguagesJavascriptJavaScript Function length property

JavaScript Function length property

The Javascript Function.length property of the function object in Javascript is used to return the number of parameters required by a function.

Syntax:

function.length

Parameters: This method requires no parameters.

Return: Return type is number.

A few examples are given below for a better understanding of the method.

Example 1: When the number of parameters is zero.

Javascript




<script>
    // Creating function name func
    // When no parameters are given
    function func1(){}
    console.log(
    "The number of parameters required by "+
     "the function are: ", func1.length)
</script>


Output:

The number of parameters required by the function are:  0

Example 2: When the number of parameters is greater than one.

Javascript




<script>
    // Creating function name func
    // When one parameters are given
    function func1(a){}
    console.log(
    "The number of parameters required by the func1 are: ",
      func1.length)
    // When two parameters are given
    function func2(a, b){}
    console.log(
    "The number of parameters required by the func2 are: ",
     func2.length)
    // When three parameters are given
    function func3(a, b, c){}
    console.log(
    "The number of parameters required by the func3 are: ",
     func3.length)
    // When four parameters are given
    function func4(a, b, c, d){}
    console.log(
    "The number of parameters required by the func4 are: ",
     func4.length)
</script>


Output:

The number of parameters required by the func1 are:  1
The number of parameters required by the func2 are:  2
The number of parameters required by the func3 are:  3
The number of parameters required by the func4 are:  4

Example 3: When an array of arguments is given

Javascript




<script>
    // Creating function name func
    // When array of arguments are given
    function func4(...args){}
    console.log(
    "The number of parameters required by the func4 are: ",
     func4.length)
</script>


Output:

The number of parameters required by the func4 are:  0

We have a complete list of Javascript Function methods, to check those please go through this Javascript Function Complete reference article.

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 3 and above
  • Safari 1 and above
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS