Skip to content

Instantly share code, notes, and snippets.

@EQuimper
Created November 29, 2016 06:26
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 EQuimper/eac1ffb1626da70b4fb7a849a9a7f4fd to your computer and use it in GitHub Desktop.
Save EQuimper/eac1ffb1626da70b4fb7a849a9a7f4fd to your computer and use it in GitHub Desktop.
Object literal for replace switch
function getDrink (type) {
var drinks = {
'coke': 'Coke',
'pepsi': 'Pepsi',
'lemonade': 'Lemonade',
'default': 'Default item'
};
return 'The drink I chose was ' + (drinks[type] || drinks['default']);
}
var drink = getDrink('coke');
// The drink I chose was Coke
console.log(drink);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment