How to test if a parameter is provided to a function?

This is a very frequent pattern.

You can test it using

function parameterTest(bool) {
  if (bool !== undefined) {

You can then call your function with one of those forms :

 parameterTest();
 parameterTest(someValue);

Be careful not to make the frequent error of testing

if (!bool) {

Because you wouldn’t be able to differentiate an unprovided value from false, 0 or "".

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)