JavaScript Promises and Async/Await with Loops

The Example We Will Build Up To

A Classic Way of Delaying Code Execution

setTimeout(inputFunction, timeInMilliseconds);
1 | print immediately
2 | print after one second

Declaring A Promise

1 | print immediately
2 | print me after one second
1 | print immediately
This is a fake error

Async / Await

1 | print immediately
2 | print after one second

Async / Await in Loops

Using a for loop

Using a while loop

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nafeu Nasir

Nafeu Nasir

is a musician and full-stack web developer from Toronto, Canada who studied Computer Science and Linguistics at the University of Toronto.