In this short blog post, we'll understand how we could find the number of arguments a JavaScript function accepts.
JavaScript's function object consists of a length property which could be used to get the number of arguments a JavaScript function accepts.
- function sum(arg1, arg2, arg3) {
- return arg1 + arg2 + arg3;
- }
- console.log(sum.length)
-
In the above code the console.log method will output 3 since the sum function accepts 3 arguments.