Skip to content

Instantly share code, notes, and snippets.

@MilanGrubnic70
Last active August 29, 2015 14:00
Show Gist options
  • Save MilanGrubnic70/11095209 to your computer and use it in GitHub Desktop.
Save MilanGrubnic70/11095209 to your computer and use it in GitHub Desktop.
Ternary Operator

#Ternary Operator

#####This is a shorthand statement for a simple if...else statement. It is a useful tool in situations where you have an extremely simple if...else statement where you are trying to assign a value to a variable.

boolean_expression ? true_expression : false_expression

grade = 88  
status = grade >= 70 ? "pass" : "fail"  
=> pass  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment