When you've been writing code for a good while, you start looking at ways to speed up the process. Perhaps the most obvious method to achieve this is to write fewer lines of code.
if/else statement looks like this:
Look at that: five lines of code. We can do better than that, right?
condition ? expr1 : expr2. The above code can be condensed to the following.
What we’re saying is that if
foo is greater than
baz is assigned the value of 10. If not,
baz is 20.
Personally, I’ve found that a major drawback of using syntax like this is that the code becomes harder to parse when reading through it. Your mileage may vary, but just like omitting the braces of single-line
if statements, it takes just that extra beat of brain-power to comprehend.