Posts

Showing posts with the label Asynchronous JavaScript

Understanding Synchronous and Asynchronous JavaScript - paRt_2: JavaScript - its DiFFereNt

Image
In the first part of this post , we saw how the concepts of synchronous and asynchronous are perceived in JavaScript. In this second part, Mr K  appears again to help us understand how the setTimeout() and AJAX APIs work. Let's go back in past to the story of Mr. K and the date you wanted to go on! but what if you leave a task for Mr. K before outing and tell him that he can only begin to work on this task five hours after  he got your message.   He isn’t happy about it! But why does Mr H leave a message in the queue instead of directly contacting Mr K? Because as I mentioned in the first part, the only way to contact Mr K is by leaving a message to him via phone call — no exceptions., remember, he doesn’t take a new message until he is done with the current one, and if he takes yours, he has to wait for five hours to even start on the task. So, to not be wasteful of time, he brings in a helper, Mr H. Instead of waiting, he asks Mr H to leave a new message for...

Understanding Synchronous and Asynchronous JavaScript - paRt_1 : JavaScript - its DiFFereNt

Image
In JavaScript Synchronous and Asynchronous are very important concepts. Beginners might find them difficult to learn. When two or more things happen at same time then it is Synchronous and when they don't that's Asynchronous . These definitions are easy to understand but it's complicated than it looks from here. So let's dig a little deeper.  You’d probably call a normal function in JavaScript synchronous, right? And if it’s something like setTimeout() or AJAX that you’re working with, you will refer to it as being asynchronous, yes? What if I tell you that both are asynchronous in a way? Let's understand with an example. We'll get help from Mr. K, Scenario 1:-> Mr. K is trying Synchronicity  Here’s the setup: Mr K is someone who can answer tough questions, and carry out any requested task. The only way to contact him is through a phone call. Whatever question or task you got, in order to ask Mr K’s help to carry it out; you call him...