How can you get the total number of arguments passed to a function?

1 Answer(s)

Using arguments.length property, we can get the total number of arguments passed to a function. For example −

function func(x){
   console.log(typeof x, arguments.length);
}
func();                //==> "undefined", 0
func(1);               //==> "number", 1
func("1", "2", "3");   //==> "string", 3
Supporter Answered on August 15, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.