Created
April 21, 2021 21:54
-
-
Save nelsonfncosta/6c144bf52a547834d524f943eee9ce19 to your computer and use it in GitHub Desktop.
Shorthand example for switch statement
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
// Longhand | |
switch (data) { | |
case 'a': | |
test1(); | |
break; | |
case 'b': | |
test2(); | |
break; | |
case 'c': | |
test3(); | |
break; | |
// And so on... | |
} | |
// Shorthand | |
var data = { | |
a: test1, | |
b: test2, | |
c: test3 | |
}; | |
data[something] && data[something](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment