Variadic Function in Java Script

Zia

I have a js function as below

function showMsg(id) {
      id = id! = null && id != undefined ? id : '';
      //doing some task
    }

I am calling above function from two different event one with parameter and another without parameter as below,

Call from first event,

showMsg(id);

Call from second event

showMsg();

As i know JS function is variadic in nature so is it right way to call the function? Will it cause any problem in older version of brwoser?

Any help and suggesstion must be appreciated.Thanks

Nina Scholz

You can shorten it to

id = id || '';

All falsy values are converted to an empty string. So as undefined, which is the value for calling the function without a parameter.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related