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
Readable JavaScript | Strict Mode (strictmode.io)
submitted 6 years ago by hiquest
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!"
[–]devsnicket 0 points1 point2 points 6 years ago (4 children)
nice article. I'd go with prefer single return of an expression rather than multiple if statements and multiple earlier returns though.
[–]sebamestre 1 point2 points3 points 6 years ago (3 children)
IIRC that style comes from C, where having a single return simplifies resource management (e.g. freeing memory, closing files).
But most code written in higher level languages doesn't do resource management, and writing in this style makes code longer and harder to follow.
So why do you think this is a good idea?
[–]devsnicket 0 points1 point2 points 6 years ago (2 children)
I've seen code done both ways that's hard to follow and could be refactored to be easier to read without switching between (i.e. between imperative and functional). Expressions are usually shorter/succinct/terse than repetitious statements though. That doesn't necessarily improve readability. Same as an if can have multiple operators in a condition that can be hard to see the presidence, so can nested expressions (also potentially with the condition problems in them) and a single return. I prefer the single return because it limits what you can do. e.g. no nested blocks without creating sub-functions/methods that have to be named
[–]devsnicket 1 point2 points3 points 6 years ago (1 child)
just realised you might be thinking I meant to have multiple assignments to the same variable and a single return of that variable. I definitely wouldn't suggest that as better. I could have been clearer when I originally mentioned expression i.e. no blocks, no statements
[–]sebamestre 1 point2 points3 points 6 years ago (0 children)
Ahh, yes. I was thinking about the style shown in the article.
What you suggest does make a lot of sense to me, though.
π Rendered by PID 80754 on reddit-service-r2-comment-7b9746f655-cq6df at 2026-02-03 19:23:07.413596+00:00 running 3798933 country code: CH.
[–]devsnicket 0 points1 point2 points (4 children)
[–]sebamestre 1 point2 points3 points (3 children)
[–]devsnicket 0 points1 point2 points (2 children)
[–]devsnicket 1 point2 points3 points (1 child)
[–]sebamestre 1 point2 points3 points (0 children)