3 ms·
What about: const eldest = 24>41 ? "Liz" : "Ike";
by esperent 4y ago
What about:
const eldest = 24>41 ? "Liz" : "Ike";
- flappyeagle 4y agoThis is ugly and hard to read compared to trailing if. They’re about the same for a one-liner but if you have anything more complex, Ruby style trailing if is far superior.
- esperent 4y ago> This is ugly and hard to read compared to trailing if. For short statements like the examples given here, it's not ugly and it's easy to read. Whether it's easier/harder to read than trailing if depends on how familiar you are with each syntax. I don't think either is superior in this example. I agree ternaries are not suitable for long complex statements. However, I don't think trailing if is suitable for long complex statements either. I've generally only seen it used in simple cases.