loading...

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

FULL DISCUSSION
 

In it's simple use, the ternary operator is rather helping than hindering the reading flow, as illustrated by the example:

// w/o ternary operator:
let result;
if (condition) {
  result = CONDITION_MET;
} else {
  result = CONDITION_NOT_MET;
}

// w/ ternary operator:
const result = condition ? CONDITION_MET : CONDITION_NOT_MET;

However, in golfed or minified code, one usually finds abominable abuses of the ternary operator within already complicated statements that reduce readability. Only use them there, never the code you work on.

code of conduct - report abuse