loading...

re: What do you think about the ternary operator? VIEW POST

FULL DISCUSSION
 

I'm a big fan of ternaries in JS, because IMO expressions are better than statements for reducing cognitive load, which is generally my primary goal when coding.

However, I find that my personal favourite formatting for ternaries is:

condition
  ? valueIfTrue
  : valueIfFalse;

To be clear though, I do believe that if/else is better for readability (especially for less experienced developers), and I prefer languages which only have expressions (and consequently their if/elses are expressions too). But for languages that aren't as nice as that, I always prefer ternaries for assignments.

code of conduct - report abuse