If Then Else Ternary Expression

By Xah Lee. Date:

In JavaScript and language that borrows C syntax, there's “if expression”, often called ternary expression.

Example:

if ( x === 1 ) { x = 2; } else { x = 3; }

vs

( x === 1 ? x = 2 : x = 3 )

the if expression has all the advantages:

What if you write all if statements as if expressions (test ? true : false)

If you have a question, put $5 at patreon and message me.