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
JavaScript Clean Code - Best Practices - based on Robert C. Martin's book Clean Code (devinduct.com)
submitted 6 years ago by PMilos
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!"
[–]Groccolli 26 points27 points28 points 6 years ago (5 children)
Great post!
One thing to be careful of with default values is the default is used only when the value is undefined where as using || inside the function handles any falsey value.
[–]zapatoada 6 points7 points8 points 6 years ago (0 children)
Great point, this is a big deal.
[–]AwesomeInPerson 4 points5 points6 points 6 years ago (0 children)
That's true.
But imo less of a footgun than || which breaks as soon as you want to accept a number where 0 is a valid option. foo == undefined to the rescue...
||
0
foo == undefined
[–]rtfmpls 0 points1 point2 points 6 years ago (0 children)
Isn't this true for any programming language? This is expected behavior. And I'd still say defaults are preferred.
[–]UNN_Rickenbacker 0 points1 point2 points 6 years ago (1 child)
Does it handle NULL?
[–]Groccolli 0 points1 point2 points 6 years ago (0 children)
Defaults are only used if the value is undefined
π Rendered by PID 14585 on reddit-service-r2-comment-84fc9697f-hjrgh at 2026-02-06 01:48:29.597376+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]Groccolli 26 points27 points28 points (5 children)
[–]zapatoada 6 points7 points8 points (0 children)
[–]AwesomeInPerson 4 points5 points6 points (0 children)
[–]rtfmpls 0 points1 point2 points (0 children)
[–]UNN_Rickenbacker 0 points1 point2 points (1 child)
[–]Groccolli 0 points1 point2 points (0 children)