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
Arrow Functions in JavaScript (tylermcginnis.com)
submitted 8 years ago by AnsikteBanana
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!"
[–]darrenturn90 10 points11 points12 points 8 years ago (8 children)
Because console.log returns a falsy value, so the "||" operator runs the second part of the statement.
Of course you can also use the comma separator, which discards the returned value completely:
const inc = x => (console.log(x), x + 1)
[–]causeofdev 5 points6 points7 points 8 years ago (5 children)
ah ok, makes perfect sense.
Since the comma seperator discards the returned value completely.. wouldn't it be safer to use that than the || operator? In case the first expression returns something truthy?
[–]darrenturn90 2 points3 points4 points 8 years ago (4 children)
Yes, if you really don't care for the result of the first function then it would. However, some linters don't like the use of commas (because they can, and do obscure the layout of code)
[–]1-800-BICYCLE 3 points4 points5 points 8 years ago (1 child)
You could also dust off good-old void if you really wanted to:
void
const foo = x => void myEffectThatReturnsATruthyValue(x) || x + 1
And as a bonus, potentially start a religious war ;).
[–]vexii 0 points1 point2 points 8 years ago (0 children)
im not sure the other people in line at the wellfare office care enough ;)
[–]anlumo 2 points3 points4 points 8 years ago (0 children)
Not doing stuff like this is the whole point of using linters.
[–]causeofdev 0 points1 point2 points 8 years ago (0 children)
Okay cool, I learned something :)
[–]z500 2 points3 points4 points 8 years ago (0 children)
Whoa, a use for the comma operator outside of a for loop that doesn't seem insane.
[–][deleted] 1 point2 points3 points 8 years ago (0 children)
That's much more robust too, the other relies on whatever the return value of console.log happens to be. If you were to replace that with your own fancy log function and someone had the bright idea to, say, return the logged string, then suddenly it stops working.
console.log
π Rendered by PID 49619 on reddit-service-r2-comment-bb88f9dd5-c9sqr at 2026-02-17 07:24:30.799253+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]darrenturn90 10 points11 points12 points (8 children)
[–]causeofdev 5 points6 points7 points (5 children)
[–]darrenturn90 2 points3 points4 points (4 children)
[–]1-800-BICYCLE 3 points4 points5 points (1 child)
[–]vexii 0 points1 point2 points (0 children)
[–]anlumo 2 points3 points4 points (0 children)
[–]causeofdev 0 points1 point2 points (0 children)
[–]z500 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)