JavaScript is single-threaded, which means it can only execute one thing at any one time. Asynchronous code executes when all synchronous code is completed.

The syntax of async and await is that an operation marked as await can only occur inside a function marked async, and it marks the point in the code at which to continue executing when the synchronous code is complete.

In JavaScript versions that don't have these features yet, you can emulate it using setTimeout with a delay of 0. setTimeout executes the callback function asynchronously. If you put all statements after await inside a setTimeout block, you can see that the behavior is the same: