How async await makes javascript asynschronous?
It doesn't. It is a tool to manage code that is already asyncronous.
As javascript is synchronous
It isn't. It runs a single main event loop and has rules for when stuff is handled outside of that loop.
when we use async await it wait for the await statement to be completed before going to next statement, so technically this is synchronous
The function containing the await
statement goes to sleep until the promise (on the RHS of the await
statement) resolves and the main event loop is free to pick the function up again.
Functions containing await
statements must be marked with the async
keyword which makes them return a promise.
The main event loop continues processing outside of that function where the calling function has access to the (unresolved) promise returned by the function marked as async
.