DEV Community


Discussion on: Easy refactor ternary conditions to if else

savagepixie profile image

The ternary could have been more readable if each part of the expression had its own line, but other than that, it's not particularly difficult to read: is thus truthy? Then do this, else is the next element truthy? Then do this, else...

I honestly fail to see how a function with so many nested returns is more readable. I could see a case for a bunch of else if statements, if one is not used to reading ternaries. But this function within a function within a function just seems more complicated to read to me.

danielpdev profile image
danielpdev Author

For me, converting the ternary expression to a function within a function was far more readable.
I had multiple condition for every nested ternary expression and it was hell.

Think about if you have to add some code for one of the nested conditions, for me it's just more easier to have it like that.

It's also not mandatory to leave it like that, I find it easy to refactor the function and not a nested ternary that is on the same line.