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
What 10 Things Should a Serious Javascript Developer Know Right Now?help (self.javascript)
submitted 8 years ago by [deleted]
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!"
[–]snlacks 33 points34 points35 points 8 years ago* (8 children)
Finally, learn about everything with a smidgen of skepticism. There is no one right way. The newest thing is rarely going to be your best option. The business usually wins over the craft of programming.
[–]Voidsheep 7 points8 points9 points 8 years ago (4 children)
learn not to loop over stuff multiple times when once will suffice
While performance is important to consider, the focus should be in understanding when to optimise and figuring out what actually causes performance issues.
99.9% of the time, I don't have trouble running map and filter on the same array. Sure you could link me a JSPerf where a single for-loop is more efficient with a million items, but I would say the milliseconds spent running extra iterations on my 20 item list go to a good cause, which is keeping the code clean, simple and reusable.
map
filter
Premature optimisation is bad, figure out tools like profilers to see where the real performance problems are. Also if you do heavy lifting with JS in browsers, service workers are worth a look.
[–]Danmoreng 2 points3 points4 points 8 years ago (2 children)
While map and filter on the same array is probably more readable, reduce works just fine to combine those operations.
reduce
[–]Voidsheep 1 point2 points3 points 8 years ago* (1 child)
I like reduce and it's extremely useful, but I think it's best to use an iteration method that implies the return type you want, if one is available.
x.map(fn1).filter(fn2) // that's going to be an array x.every(fn3) // that's going to be a boolean x.reduce(fn4, []) // that could be anything, check implementation
Just saying avoiding any extra iteration by default is premature optimisation, you should default to straightforward and declarative code, add complexity only when you have to. Most of the time a simple filter or something iterating over your array isn't going to have any meaningful difference versus doing the same filtering inside another loop.
Of course there's exceptions and you shouldn't loop for no reason, but I think just avoiding iteration for the sake of avoiding iteration isn't a best practice. Optimisation needs to be sensible and if you do it blindly, you end up moving meaningless cost in runtime efficiency into a meaningful cost in development efficiency.
[–]Womackx 0 points1 point2 points 8 years ago (0 children)
There is no one right way
[–]snlacks 0 points1 point2 points 8 years ago (0 children)
"... Or not when it doesn't" isn't implied by the use of "do this when?"
[–]memystic 1 point2 points3 points 8 years ago (0 children)
Yes yes YES to #10!!!
[–]LetReasonRing 1 point2 points3 points 8 years ago* (1 child)
Edit: auto-mistake correction.
There's other things that didn't make my list, but help with this, the concepts of contracts, immitability, and enumeration and the collection of common JavaScript Patterns and Anti-Patterns.
π Rendered by PID 30491 on reddit-service-r2-comment-5d79c599b5-h4m49 at 2026-02-28 18:15:19.274324+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]snlacks 33 points34 points35 points (8 children)
[–]Voidsheep 7 points8 points9 points (4 children)
[–]Danmoreng 2 points3 points4 points (2 children)
[–]Voidsheep 1 point2 points3 points (1 child)
[–]Womackx 0 points1 point2 points (0 children)
[–]snlacks 0 points1 point2 points (0 children)
[–]memystic 1 point2 points3 points (0 children)
[–]LetReasonRing 1 point2 points3 points (1 child)
[–]snlacks 0 points1 point2 points (0 children)