Created
December 29, 2021 02:46
-
-
Save justinpage/832230629b7a44e02c0d5d7dc1d2464e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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