r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

1

u/swyx Mar 19 '19

brendan eich even recommends this and i dont understand it. its obvious that || is easier to use than comma operator plus parens.

8

u/seiyria Mar 19 '19

I did say it's more obnoxious to use the comma operator. I do not recommend it, I just wanted to offer an alternative for those that might like the syntax better. There are some cases where the comma operator is more useful / easier to use, but I can't say I recommend using it in general as it creates code that's easier to forget about, which might create some unintentional side effects.

5

u/FormerGameDev Mar 19 '19

Many people have rules preventing the use of bool operators as flow control. With good reason.

3

u/NeatBeluga Mar 19 '19

Like a ternary operator?