Ternary Operator — Conditional Breakdown

The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy. This operator is frequently used as a shortcut for the if statement.
  • exprIfTrue: This is what would happen if the condition expression came back as True.
  • exprIfFalse: This is what would happen if the condition expression came back as False.
1. false
2. null
3. NaN - (not a number)
4. 0
5. undefined
6. (" ") - even an empty string
const basicDrinkExample = (
<h1>
{ age >= drinkingAge ? 'Buy Drink' : 'Do Teenage Stuff' }
</h1>
);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store