Skip to content

Instantly share code, notes, and snippets.

@justinpage
Created December 29, 2021 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinpage/832230629b7a44e02c0d5d7dc1d2464e to your computer and use it in GitHub Desktop.
Save justinpage/832230629b7a44e02c0d5d7dc1d2464e to your computer and use it in GitHub Desktop.
// If there is no break then the execution
// continues with the next case without any checks
// This might be an interesting way to stagger actions
//
// Clever, but maybe would be too unreadable
let a = 2 + 2;
switch (a) {
case 3:
console.log( 'Too small' );
case 4:
console.log( 'Exactly!' );
case 5:
console.log( 'Too big' );
default:
console.log( "I don't know such values" );
}
// another example that groups cases
let b = 3;
switch (b) {
case 4:
console.log('Right!');
break;
case 3: // (*) grouped two cases
case 5:
console.log('Wrong!');
console.log("Why don't you take a math class?");
break;
default:
console.log('The result is strange. Really.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment