Asynchronous Programming

What is asynchronous and how does it differ from synchronous?

After watching the ‘What the heck is the event loop anyway?’ video, aspects of asynchronous programming are much more clear and understandable, especially compared to synchronous programming.

“The main takeaway from this video is asynchronous code is faster and non-blocking.”

The way code is read is still the same, from top to bottom. And the setTimeout function is still invoked but passed onto the WebAPI, which then handles the delay while the rest of the code is rendered. It is only until after the call stack is cleared, when the callback is brought to the call stack from the task queue. Also, even with a 0ms delay, the callback does not run immediately, and still waits for a cleared stack before running, therefore causing a slight delay. Ajax requests are similar, sending the requests to the WebAPI while executing the rest of your code, not locking up your browser to other actions. The main takeaway from this video is asynchronous code is faster, and allows callbacks to be handled by the WebAPI, while allowing the call stack to work freely and not cause traffic for the browser. While synchronous code, on the other hand, blocks up the call stack and takes longer to complete. It stops the user from performing such actions as selecting text, and clicking certain elements.