A
ternary (or conditional) operator is a more concise way of achieving the same result.
This code:
if (score > 50) {
outcome= 'passed';
}
else {
outcome= 'failed';
}
alert('you ' + outcome + ' dude !');
Is the
same as this code:
outcome = (score > 50) ? 'passed' : 'failed';
alert('you ' + outcome + ' dude !');
And is even the same as this:
alert('you ' + ((score > 50) ? 'passed' : 'failed') + ' dude !');
Note in the last example we had to put parentheses around the entire ternary operator, otherwise it would have been
ambiguous what the " + 'dude'" applied to.