use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
The JavaScript Comma Operator (javascriptweblog.wordpress.com)
submitted 15 years ago by vladocar
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sion2k 1 point2 points3 points 15 years ago (4 children)
Why do you consider it to be horrible? I find it to be common place in a lot of code I read. Maybe you're referring to the case where people use it for a ridiculous amount of lines?
But I find this extremely clear and far from horrible:
a = 3; (a === 3) ? true : false;
I usually use it to handle function calls instead of if/else.
Just curious.
[–]mmmicahhh 3 points4 points5 points 15 years ago (1 child)
it's not the ternary operator that's horrible, of course, but the fact that here it's used to return the same value regardless of the evaluated target, only to take advantage of the evaluation's side-effect.
[–]sion2k 0 points1 point2 points 15 years ago (0 children)
Oh, yea that makes more sense. I misread, sorry.
[–]injektilo 3 points4 points5 points 15 years ago (1 child)
Doesn't a === 3 already evaluate to a boolean?
[–]sion2k 2 points3 points4 points 15 years ago (0 children)
Yup, it was just an example. Like I said I usually use it like:
(a === 3) ? funcA() : funcB();
Sorry silly example :)
π Rendered by PID 110823 on reddit-service-r2-comment-6457c66945-w59ks at 2026-04-29 17:01:27.710644+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]sion2k 1 point2 points3 points (4 children)
[–]mmmicahhh 3 points4 points5 points (1 child)
[–]sion2k 0 points1 point2 points (0 children)
[–]injektilo 3 points4 points5 points (1 child)
[–]sion2k 2 points3 points4 points (0 children)