Created
August 12, 2021 00:41
-
-
Save sorie/9b47bf24a27bc8671f5a70e371b3f54a to your computer and use it in GitHub Desktop.
javascript tip : ternary operator
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
//bad code | |
function getResult(score) { | |
let result; | |
if(score > 5) { | |
result = 'up'; | |
} else if (score <= 5) { | |
result = 'down'; | |
} | |
return result; | |
} | |
//good code | |
function getResult(score) { | |
return score > 5 ? 'up' : 'down'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment