Skip to content

Instantly share code, notes, and snippets.

@ShawnStringfield
Created May 3, 2018 15:36
Show Gist options
  • Select an option

  • Save ShawnStringfield/c88876e5af6a2a522a7553e62e5c1105 to your computer and use it in GitHub Desktop.

Select an option

Save ShawnStringfield/c88876e5af6a2a522a7553e62e5c1105 to your computer and use it in GitHub Desktop.
Replacing switch statements with Object literals
// https://toddmotto.com/deprecating-the-switch-statement-for-object-literals/
function getDrink (type) {
return 'The drink I chose was ' + {
'coke': 'Coke',
'pepsi': 'Pepsi',
'lemonade': 'Lemonade'
}[type];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment