Javascript – if else and switch

if, else, else if and switch are condition statements and are used when you want to execute a block of statements according to a condition.

if (condition) { statement(s) }
, <span>Javascript – if else and switch</span>, KandZ
if (condition) {
   statement(s)
} else {
   statement(s)
}
, <span>Javascript – if else and switch</span>, KandZ
if (condition) {
   statement(s)
} else if (condition) {
   statement(s)
} else {
   statement(s)
}
, <span>Javascript – if else and switch</span>, KandZ

Instead of having multiple if statements you can use switch

switch(expression) {
  case a:
     statement(s)
     break;
  case b:
     statement(s)
     break;
  case b:
     statement(s)
     break;
   default:
     statement(s)
, <span>Javascript – if else and switch</span>, KandZ
101460cookie-checkJavascript – if else and switchJavascript – if else and switch

Related posts