DEV Community

Discussion on: Nested Conditional Operators

Collapse
 
nestedsoftware profile image
Nested Software • Edited

No worries. In that case I think I’d prefer just (pseudocode):

if (invalid1)
    return error1
if (invalid2)
    return error2
etc...

I think it’s more straightforward.

Update:

The use of the ternary operator for this seems possible, but in my opinion it's leaning in the direction of being cute for cute's sake rather than really being useful. At the very least I would argue it's not idiomatic js, and if there is a benefit to it at all, I don't think it's significant enough. In general I like the idea of using the idiomatic approach for a given language unless there is really quite a strong reason not to.

All that being said, if you and your team are comfortable with this code, I don't think using it is the end of the world.