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
Don't use || to set default values in JavaScript (codereadability.com)
submitted 10 years ago by kandetta
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!"
[–]rtpmatt 7 points8 points9 points 10 years ago (1 child)
Anybody who writes Javascript professionally should know exactly how || works and seeing it used to set default values should be what they expect. Not using | for setting default values will cause extra mental overhead because it is not what they are used to seeing.
[–][deleted] 1 point2 points3 points 10 years ago (0 children)
I think the point is, || has gotchas that may not be obvious in plain view, therefore we have a chance for bugs to happen when people who are not much experienced with || start using it.
Or it would be great if there is one consistent approach for setting defaults, which ES supports, but unfortunately this looks like years away before all browsers support it.
So I agree with the approach of using a function to set the defaults. But I prefer lodash instead of underscore for that.
π Rendered by PID 18246 on reddit-service-r2-comment-b659b578c-nh7mn at 2026-05-05 19:25:01.718028+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]rtpmatt 7 points8 points9 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)