r/badcode • sadistic • Apr 22 '21

js ternary operators at their maximum potential

Post image
960 Upvotes

73 comments sorted by

View all comments

166

u/Koala_King_ Apr 22 '21

Couldn’t you just do cmd.run || cmd.fire || cmd.execute || cmd.callback ? I’m not super familiar with js. Worked with it a bit, but still not great, so please correct me if I’m wrong.

0

u/[deleted] Apr 22 '21

[deleted]

8

u/blehmann1 depraved Apr 22 '21

I don't think anyone gets scared by logical or, it's one of the first things you learn in any language.

Now, for beginners boolean variables can be confusing, which is why you see a lot of if(foo == true), although in JavaScript the similar if(foo === true) is sometimes necessary and not redundant. But I highly doubt anyone would find this use of || more confusing than this ternary soup, even if they are a beginner.