Created
May 3, 2018 15:36
-
-
Save ShawnStringfield/c88876e5af6a2a522a7553e62e5c1105 to your computer and use it in GitHub Desktop.
Replacing switch statements with Object literals
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
| // 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