JavaScript Synchronous-and-Asynchronous
JavaScript Synchronous-and-Asynchronous
Synchronous and
Asynchronous
2 Predictable
The order of execution is predictable and easy to follow.
3 Sequential
Each operation waits for the previous one to finish.
Asynchronous Operations
1 CallStack 2 Call Back Queue 3 Event Loop
CallStack will not wait if The callback queue is a data structure that Event loop takes the next
there is any delay in the holds callback functions waiting to be callback from the callback
code. executed. These callbacks are added to the queue and pushes it onto
queue when an asynchronous operation the call stack for execution.
completes.
Characteristics of Asynchronous Operations
Callbacks are functions passed Promises help to avoid the Promises can be chained
as arguments to other functions "callback hell" problem by together to create complex
and executed once the providing a cleaner and more asynchronous flows, making the
asynchronous operation readable syntax for code more maintainable and
completes. asynchronous code. easier to understand.
Async/Await: Syntactical Sugar for Promises