ConditionalOperatorNotExpression
DRAFT

Misconception:

The syntax cond ? expr1 : expr2 is just an alternative for the if statement and is not an expression.

Incorrect

The conditional operator is not an expression

Correct

The conditional operator is not an expression

Correction
Here is what's right.

The conditional operator (often called “ternary operator”) is an expression and, as a such, evaluates to a certain value.

In a case like cond ? expr1 : expr2, the whole expression evaluates to whatever expr1 evaluates to when cond is true and to whatever expr2 evaluates to when cond is false.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.