The conditional operator provides an alternative to using the if statement for conditional logic structures.

This statement ... | Is equivalent to this statement ... |
---|---|

if (BOOLEAN-expr) expr3 else expr4 |
(BOOLEAN-expr) ? expr3 : expr4 |

If `BOOLEAN-expr` is
TRUE, then `expr3` is
evaluated. Otherwise, `expr4` is evaluated.

// If x is greater than y, assign value of a to my_var. // If y is greater than x, assign value of b to my_var. my_var = (x > y) ? a : b