This tutorial will teach you how to write a js async for loop in the most basic way possible.
We’re going to use only one variable throughout this tutorial, which will be the loop variable. The rest of the code is self explanatory and will be explained in more detail in the next lesson.
If you were to write code that is not using this new async code, you will need to wrap your code in a “setTimeout” to call the code once it has finished. It’s just a matter of knowing when to use setTimeout.
The best way to learn about async code is to read the code snippets in this article which discusses the syntax for async code.
The new async code is a big departure from the old way of doing all of this stuff. It uses a new function called async which takes a callback function. Instead of using a function that is called on a certain event, it looks at the event at a specific time. So rather than having to write a function that is called on a given event, you can just write one that is called with a callback and then add that callback to the event object.