Skip to content

Instantly share code, notes, and snippets.

@huy-tran
Created February 13, 2016 22:35
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 huy-tran/721d583d0ba941487fb7 to your computer and use it in GitHub Desktop.
Save huy-tran/721d583d0ba941487fb7 to your computer and use it in GitHub Desktop.
Using Object Literal look up instead of Switch
function getHobbyOf(name) {
var hobby = {
'Huy': 'Guitar',
'Tram': 'Photography',
'default': 'Out of survey'
};
return hobby[name] || hobby['default'];
}
getHobbyOf('Huy'); // log 'Guitar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment