As to the need for this sort of coding:
You can sometimes use the ternary operator to reduce complexity:
For example, I have a web page which needed to verify that at least two out of three specific text fields had values entered. The if/else logic looked pretty ugly, but the ternary operator made it a one-liner to determine how many fields were filled in:
var numberFilledInFields = ( (firstName.length > 0 ? 1 : 0) +
(lastName.length > 0 ? 1 : 0) +
(zipCode.length > 0 ? 1 : 0) );
if (numberFilledInFields < 2)
{
validation = false;
return;
}
This solution appears quite elegant and easy to read than some alternatives.