How to write a ternary operator (aka if) expression without repeating yourself

Personally I find the best way to do this is still the good old if statement:

var value = someArray.indexOf(3);
if (value === -1) {
  value = 0;
}

Leave a Comment