Asynchronous Javascript- Promises, Async & Await

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

Below 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. That's 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 code 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". A promise is an object which handles asynchronous code. It will eventually resolve successfully or fail. This is how a promise handles an error. The fetch function is a promise. Promise.all takes an array of promises and returns a single promise which resolves after all of the given promises have resolved. It returns an array of the results. Promise.any returns the result from the first settled Promise. Promise.allSettled will return a promise with an array of results from the given promises, errors and all. ES2017 introduced async and await functions. Fetching with async and await.