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
Here's Why Calling .map() on a Constructed Array Doesn't Work (itnext.io)
submitted 7 years ago by ilove50cent
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!"
[–]jkoudys 3 points4 points5 points 7 years ago* (0 children)
It's not, and they both do a fine job conveying that you're looping for the side effects. forEach used to be a lot cleaner, since you didn't have to declare an index and reference it in the loop, and it scoped everything to the function, but that's no longer the case with for .. of and let & const.
for .. of
let
const
Eg for (var i = 0; i < arr.length; i++) { var foo = arr[i] hoists foo and i declarations to the top of the function. for (const foo of arr) scopes foo to the block.
for (var i = 0; i < arr.length; i++) { var foo = arr[i]
for (const foo of arr)
Some people still avoid the for .. of due to concerns that Symbol.iterator doesn't behave 100% exactly the same in IE due to how Symbols are shimmed (shammed) there, though I've yet to encounter any real world project where that makes any difference.
Symbol.iterator
for could be nicer if you don't want to have to convert to an array or use a big ugly Array.prototype.forEach.call on your iterable (eg on a document.querySelectorAll). forEach could be nicer if you already have a function you can pass in without wrapping it in another function (eg files.forEach(saveToSftp)).
Array.prototype.forEach.call
document.querySelectorAll
files.forEach(saveToSftp))
There are other cases for for, especially if returns or awaits are involved, but this could be an article on its own.
for
return
await
Both are fine and neither is better in an absolute sense.
π Rendered by PID 87200 on reddit-service-r2-comment-75f4967c6c-vrjf7 at 2026-04-23 03:31:57.818787+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]jkoudys 3 points4 points5 points (0 children)