Synchronous vs Asynchronous

saba ahmadi
Jul 21, 2017 · 1 min read

First let’s define them in easy way to understand them, Two or more things are synchronous when they happen at the same time, and asynchronous when they don’t.

Synchronous code is a code which line of codes run in sequence order.

Asynchronous code is different from that which it allows the code which is written write after that to be executed immediately without waiiting.

Let me give an example imagine you are in a queue and you are waiting for your turn in queue to order something you should wait for all people which came before you to order their stuffs. This example is kind of the same as ruuning some Synchronous code.

Now imagine you are in a resturant and you want to order something, you don’t have to wait for all other people who came before you to finish their food to order your food at the same time that they’re eating you can order. That’s like Asynchronous code.

Now let’s talk about this concept in JS, as we know JS is single threaded but it allows Asynchronous code! So what does it mean then? It means that we have cuncurrency but we don’t have parallelism here. Like if it is fast enough it can switch between different task efficiently enough so diffrent stuff are making progress.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade