DEV Community

Discussion on: Avoid use IF on our JS scripts

Collapse
uuykay profile image
William Kuang • Edited on

No way is nested ternaries easier to read than if/else if statements. Teraries should be used for if/else statements only. Nesting them is insane. It reminds me of if/else if operations in Excel.

Collapse
damxipo profile image
Damian Cipolat Author

Yes is similar, the Excel formulas are something like fp

Collapse
miralize profile image
Sean O'Grady

what do you mean by this?

Thread Thread
uuykay profile image
William Kuang

If you've ever had to write a conditional in Microsoft Excel, you'll be familiar with this. Check out this article to see what I mean: exceljet.net/excel-functions/excel....

Excel doesn't have if/else if statements, it only has if/else which is the same as a ternary. Do you really think reading this is easier?
=IF(C6<70,"F",IF(C6<75,"D",IF(C6<85,"C",IF(C6<95,"B","A"))))

Thread Thread
damxipo profile image
Damian Cipolat Author

It is just a proposal, for me an excel formula is just as ugly as an if..else..elseif with nesting.