1. Home
  2. Javascript
  3. Switch case

Runs through a set of cases and executes the code when the condition is met.

#javascript#conditional
switch(myVar){
    case "a" :
    // Execute some code if myVar equals "a"
    break;

    case "b" :
    case "c" :
    // Execute some code if myVar equals "b" or "c"
    break;

    default :
    // If all cases fail run this
}
copy
Full Javascript cheatsheet