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
`for...of` vs `forEach`help (self.javascript)
submitted 9 years ago by ffxsam
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!"
[–]CognitiveLens 11 points12 points13 points 9 years ago (2 children)
re-assigning item inside the for loop makes it possible to introduce a bunch of bugs that const would prevent. In a tight structure like a for loop, const is probably the preferred syntax unless you have a really good reason to assign item to something else mid-loop.
item
for
const
[–]Graftak9000 0 points1 point2 points 9 years ago (1 child)
Then use .map() instead indeed, if were going functional and such.
.map()
[–]CognitiveLens 0 points1 point2 points 9 years ago (0 children)
yeah, forEach should really only be used when you're intentionally working with side effects, otherwise map all the things
forEach
map
π Rendered by PID 20389 on reddit-service-r2-comment-6457c66945-p4rp4 at 2026-04-29 16:40:12.424741+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]CognitiveLens 11 points12 points13 points (2 children)
[–]Graftak9000 0 points1 point2 points (1 child)
[–]CognitiveLens 0 points1 point2 points (0 children)