How to determine function have param or not

Viewed 50

How can i determine if function have param or not

Like

function Foo(bar){}

And

function Foo(){}

I tried to use Foo.arguments but always return null at both

How can i know when function have param or know param length?

1 Answers

You can access the number of parameters a function has via .length. For example,

function Foo(bar){}
console.log(Foo.length); // 1

and

function Foo(){}
console.log(Foo.length); // 0
Related