Skip to content

Instantly share code, notes, and snippets.

@leadelngalame1611
Last active March 13, 2022 04:50
Show Gist options
  • Save leadelngalame1611/eaf43c447e46964a4b853a26ec7db133 to your computer and use it in GitHub Desktop.
Save leadelngalame1611/eaf43c447e46964a4b853a26ec7db133 to your computer and use it in GitHub Desktop.
Ternary Operators
# 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