Asynchronous Javascript- Promises, Async & Await

Asynchronous functions can run in the background while the rest of your script continues to run.

Below is a simple example. There are 3 lines of code which take various amounts of time to execute. Even though the slowest line of code is read in first, the quickest code will render output to the console the fastest.

This is great if you're trying to render a page quickly, but if your code is dependent on getting a value from somewhere, then you may not want the rest of your script to execute until a condition is satisfied.

Traditionally, coders used callback functions to force Javascript to behave synchronously.

A chain of callbacks can get unwieldly, thus the term callback hell.

ES2017 introduced async and await functions. Tutorial