3 ms·
It's not syntactic sugar. The ternary operator usually appears in imperative languages (or should I say, languages which are not expression-oriented) where the
by the_af 12y ago
It's not syntactic sugar.
The ternary operator usually appears in imperative languages (or should I say, languages which are not expression-oriented) where the if-then-else construct statement is NOT an expression, and possibly has side-effects. Therefore, you need an alternative construct that really is an expression and evaluates to something.
The syntax itself is irrelevant. If you can say the following in your favorite language:
x = if (condition) { something } else { something else }
then you don't need a "ternary operator".