Top community members
All Wiki Articles Create Wiki Article

In the past we had a dream,
to have place where we could share IT knowledge,
to ask questions without fear that someone will judge us.

Now we are a group of people who make this dream come true. ❤ 💻

If you think sharing knowledge and helping other is valuable.

join our community - Click here

JavaScript - how to check number of arguments of function?

0 contributions
11 points

Using JavaScript it is possible to check number of arguments of any function in following ways.

1. Function call arguments

Each function in JavaScript can be called with different number of arguments than are in definition.

1.1. Classic function example

// ONLINE-RUNNER:browser;

function doSomething(id, action, message) {
    console.log('Number of arguments for called function is ' + arguments.length);
}

doSomething(10, 'remove', 'Files from recycle bin removing.', 
    'File name 1', 'File name 2', 'File name...');

1.2. Arrow function example

// ONLINE-RUNNER:browser;

let doSomething = (...args) => {
    // arguments keyword is not permitted in arrow function

    console.log('Number of arguments for called function is ' + args.length);
}

doSomething(10, 'remove', 'Files from recycle bin removing.', 
    'File name 1', 'File name 2', 'File name...');

2. Function definition arguments

This approach can be used for classic and arrow function definitions.

// ONLINE-RUNNER:browser;

function doSomething(id, action, message) {
    // function logic...
}

console.log('Number of arguments for function definition is ' + doSomething.length);

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more