1. Home
  2. Javascript
  3. Switch case
#javascript#conditional

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

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
Sitemap Git repository