Member-only story
How to Interchange Promises with Async/Await in JavaScript
From my blog.
One of the things that makes JavaScript so powerful is the way it handles asynchronous behavior. From the very beginning, JavaScript has used callbacks as a way of handling a response that may take a while to complete, without preventing your program from continuing to process other logic.
Retrieving or writing something to a database, filesystem or network are all examples of something that can block your program. The example below is a read request to a filesystem where the result is handled with a callback:
Promises
Promises were introduced in ECMAScript 2015 as another way of being able to handle asynchronous behavior using a more structured pattern. The basic problem with callbacks is that if you have to handle more than…