DEV Community

Discussion on: Ternary Operators In JavaScript

Collapse
 
mjworsley profile image
mjworsley

While coding, one of the key things I try to aim for is readability and maintainability - after all, the interpreter or compiler doesn't really care how many lines you've used, but you will care when you try to read it again 6 months later.

In my experience, the ternary operator prioritizes brevity over readability. If we take this to its logical extreme, we'd be naming all our variable 'a1', 'a2' etc...

Collapse
 
swapnil7000 profile image
Swapnil7000

I have also written a blog on ternary operators please give your reviews on it.

Collapse
 
mrlarson2007 profile image
Michael Larson • Edited

I have the same feelings. I limit use of ternary operators where it makes sense to use them. Most of the time I use if statements. Reason? I want to opitimize for readability not brevity.