JavaScript Async/Await Pitfalls With ForEach

Build bug-free apps

Johannes Baum
Better Programming
Published in
2 min readFeb 26, 2021

--

Rubik’s cube
Photo by ALAN DE LA CRUZ on Unsplash.

A common pitfall in JavaScript is the usage of async/await in combination with forEach. Let’s look at an example with a simple asynchronous function (asyncPrint) that prints a value to the console. Say we want to call it sequentially for every value in an array via forEach:

--

--