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

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
сніпети з JavaScript
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести