Promise is an object that returns the value of an asynchronous operation. So you might wonder what’s an asynchronous operation. They are code that runs without blocking the execution of other code. This means different parts of your script can run at the same time without being blocked.
document.write() from executing until it finishes its own execution and so on.
This is all fine and dandy until you beed a function that queries a database or returns a payload from an API, both of which might take a considerable amount of time. Instead of waiting for the resource requests to be finished, you might want other code to be executing. You can do this by using the
Below is an example of a promise that waits for an async operation to complete before resolving. While that is happening, other can still run.