JavaScript async/await in forEach pitfalls

🔥 JavaScript trap: forEach + async/await doesn’t do what you think 😬 This one shows up a lot in interviews. ❓What’s the output order? A) 1 2 3 done B) done 1 2 3 C) done then 1/2/3 in random order D) It throws an error ❓Why doesn’t forEach “wait” for await? 💬 Drop your answer + reasoning 👇 #CodeSnatch #javascript #asyncawait #interviewprep #webdevelopment #frontend

  • text

❓Can you rewrite it so it logs 1, 2, 3 in order, then "done"?

Like
Reply

done and then 1 2 3 forEach is not promise-aware. It schedules the async functions and then continues immediately.

See more comments

To view or add a comment, sign in

Explore content categories