0 votes
in JavaScript by
What is the way to find the number of parameters expected by a function in Javascript?

1 Answer

0 votes
by

You can use function.length syntax to find the number of parameters expected by a function. Let's take an example of sum function to calculate the sum of numbers,

function sum(num1, num2, num3, num4) {
  return num1 + num2 + num3 + num4;
}
sum.length; // 4 is the number of parameters expected.
...