Created
April 19, 2021 01:44
-
-
Save jlggross/1a6a5d6d16a93912c5c6dba80047351e to your computer and use it in GitHub Desktop.
Ternary operator
This file contains 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
var gender = "male" | |
// Traditional if-else | |
if (gender === "male") { | |
console.log("Male gender.") | |
} else { | |
console.log("Other gender.") | |
} | |
// Ternary operator | |
gender === "male" ? console.log("Male gender.") : console.log("Other gender.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment