DEV Community

Discussion on: We don't need a ternary operator

Collapse
 
jeikabu profile image
jeikabu

I agree with with all your points.

But I feel like there's situations where it's arguably clearer than the alternative.

Other commenters have mentioned the functional angle, and that's really it. In many (all?) the languages that have the ternary operator if is a statement (rather than an expression). Make if an expression and ternary has no place in the world:

let a = if cond { true_value } else { false_value };
Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Note, I say we don't need the ternary because it can be replaced with general purpose binary operators. I'm not suggesting to get rid of the functionality, that'd be crazy-talk.