‹ BACK

Multi-case - single operation

Multi-case - single operation

This method takes advantage of the fact that if there is no break below a case statement it will continue to execute the next case statement regardless if the case meets the criteria.
This is an example of a single operation sequential switch statement, where four different values perform exactly the same.
var Animal = 'Giraffe';
switch (Animal) {
  case 'Cow':
  case 'Giraffe':
  case 'Dog':
  case 'Pig':
    console.log('This animal will go on Noah\'s Ark.');
    break;
  case 'Dinosaur':
  default:
    console.log('This animal will not.');
}
Read more: Stackoverflow: Switch statement multiple cases in JavaScript
switch-statement multi-case-single-operation multi-case

To check your knowledge the following tests are recommended:
Check your javascript javascript skills.