Last active
March 13, 2022 04:50
-
-
Save leadelngalame1611/eaf43c447e46964a4b853a26ec7db133 to your computer and use it in GitHub Desktop.
Ternary Operators
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
# The ternary operator is a for of syntatic sugar for an inline if/else | |
#Javascript: | |
const color = "blue" | |
console.log(color === "blue" ? "Show blue" : "Show red") | |
//output: Show blue | |
#Python | |
color = "blue" | |
print("Show blue" if color == "blue" else "Show red") | |
//output: Show blue | |
#Bash | |
color="blue" | |
[[ "${color}" == "blue" ]] && echo "Show blue" || echo "Show red" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment