Can I handle an “undefined” case in a switch statement in JavaScript?

Add a case for undefined.

case undefined:
  // code
  break;

Or, if all other options are exhausted, use the default.

default:
  // code
  break;

Note: To avoid errors, the variable supplied to switch has to be declared but can have an undefined value. Reference this fiddle and read more about defined and undefined variables in JavaScript.

Leave a Comment

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