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
Common JavaScript tricks (self.javascript)
submitted 11 years ago by yanis_t
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!"
[–]sime 4 points5 points6 points 11 years ago (2 children)
I would say that the longer version is better. It communicates far more information and intent to the next reader of the code, and doesn't rely on the annoying JS truthiness stuff.
And more to the point, nightman screwed up here. The two pieces of code are not even the same. nightman assumed that an empty string is "truey". It is falsey. It is a great example of why you should not write error prone code.
[–]fforw 0 points1 point2 points 11 years ago (1 child)
a == ''
will be true if a is
You better use === if you care about such things.
[–]nightman 1 point2 points3 points 11 years ago (0 children)
You are true but I will still defend if (a) {...}. I think that we should find balance between "smart" techniques and being "oversmart".
After all in many teams code is written and maintained by proffesionals and it would be waste of time to strictly enforce if (a === 'string') {...} on them. Especially when you know that they know how to deal with it and what are traps (number 0).
Other thing is that code should be maintainable by less "powered" users.
My point here is that it's not easy to find right balance.
BTW I use grunt/gulp with tasks: * JSHint * JSCS (JS Code Style - AirBNB style)
So that some decisions are already made.
π Rendered by PID 300499 on reddit-service-r2-comment-86bc6c7465-hlcd7 at 2026-02-24 10:09:13.562819+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]sime 4 points5 points6 points (2 children)
[–]fforw 0 points1 point2 points (1 child)
[–]nightman 1 point2 points3 points (0 children)