Put simply; a promise is a new kind of object which can be returned by a function when the actual result of the function isn’t ready yet – it’s a promise that the result is on its way. When the result arrives, the promise is resolved, and the value can be used (or any resulting error can be handled).
It means no more waiting for a function to complete before you can do something else – your program moves on, and the promise runs asynchronously until it has been completed.
The await operator waits for a Promise to resolve before continuing, rather than allowing your program to move on and continue executing while the promise resolves.
The setTimeout() function executes a function after a given amount of time defined in milliseconds. The below code prints a message to the console after a 1-second delay:
Combining await(), Promise and setTimeout() to Pause/Sleep
await new Promise(resolve => setTimeout(resolve, 3000));
await is used to wait for the result of a new Promise, which is set to resolve after a given number of milliseconds (in this case, 3000).