Created
February 13, 2016 22:35
-
-
Save huy-tran/721d583d0ba941487fb7 to your computer and use it in GitHub Desktop.
Using Object Literal look up instead of Switch
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
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