r/badcode • sadistic • Apr 22 '21

js ternary operators at their maximum potential

Post image
960 Upvotes

73 comments sorted by

View all comments

43

u/-IoI- Apr 22 '21

My boss hates me using ternary operators - I can see why now.

46

u/EnigmaticHam Apr 23 '21

Ternary statements have a legitimate use - when you have one test condition and always have two branches in your code. But when you've got more than one, just use if else.

1

u/recycle4science Apr 23 '21

Or reconsider your architecture lol

14

u/[deleted] Apr 23 '21

[removed] — view removed comment

0

u/recycle4science Apr 23 '21

Lol fair enough. I didn't really register what exactly you were saying, I was talking about more like what the op posted.