Skip to content

Instantly share code, notes, and snippets.

@nelsonfncosta
Created April 21, 2021 21:54
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 nelsonfncosta/6c144bf52a547834d524f943eee9ce19 to your computer and use it in GitHub Desktop.
Save nelsonfncosta/6c144bf52a547834d524f943eee9ce19 to your computer and use it in GitHub Desktop.
Shorthand example for switch statement
// 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