ASYNC FUNCTIONS
Async functions, also referred to by the operative keyword pair “async/await,” are the application of the ES6 Promise paradigm to ECMAScript functions. Support for async/await was introduced in the ES7 specification. It is both a behavioral and syntactical enhancement to the specification that allows for JavaScript code which is written in a synchronous fashion, but actually is able to behave asynchronously. The simplest example of this begins with a simple promise, which resolves with a value after a timeout:
let p = new Promise((resolve, reject) => setTimeout(resolve, 1000, 3));
This promise will resolve with a value of 3 after 1000ms. For other parts of the program to access this value once it is ready, it will need to exist inside a resolved handler:
let p = new Promise((resolve, reject) => setTimeout(resolve, 1000, 3));
p.then((x) => console.log(x)); // 3
This is fairly inconvenient, as the rest of the program now needs to be shoehorned...