Cover image for Mysterious JavaScript Part-I: Synchronous Js

Mysterious JavaScript Part-I: Synchronous Js

akdeberg profile image Anik Khan Updated on ・2 min read

Learning is fun. Well, I think it should be written like "Learning is fun🥱😒"
I don't know who said this but to me, learning is anything but fun. Imagine learning one of JavaScript's mysterious topics like synchronous & asynchronous programming😫😫
Could it be any harder?
Well, don't worry. I will try my best to explain some of the inner workings of javascript in a simple way so that you don't have to take the hard path. Join me!👯‍♂️
(Quite a marketing pitch, huh?😎😎)

Evolution of JavaScript

JavaScript evolved so much so that it sometimes feels like a different programming language that we used to know.
Alt Text
While this is a good thing, it sometimes can create confusion. One such confusion- Is JavaScript Synchronous or Asynchronous?

JavaScript is Synchronous

Yaay! The truth has been revealed😜. JavaScript at its core- a single-threaded, synchronous language. That basically fancy way of saying- JavaScript does one operation at a time.
While one operation is on run, others stay stand still and wait for their turn.
Alt Text
I hear you saying, what if I try to break this traditional way of executing things? I am glad that you ask. But I believe, in this case, the ladies have the answer😝😜
Protip: If you want to die sooner, come India and try breaking a line like this (referring the image).


Let's assume that I have three sentences to log in console-

Alt Text

I would get output like this-

Alt Text

The output will be in sequence. JavaScript shows output in sequence.

Hence, if I were to change the sequence of the log-

Alt Text

the output sequence will also be changed-
Alt Text

The point is, JavaScript logs the outputs in a specific order So, changing the order changes the output sequence too. The execution order is tracked & strictly maintained.

Well! Now, the important question- How does JavaScript keep track of this sequence? I mean, we need someone to play the managerial role, right? The manager keeps the rules in place & makes sure that the functions are executed in proper order. Who is this manager?

This million 💲💲💲 question will be answered in the next part. So stay tuned 😍
(images are from unsplash and timesofindia)

Posted on by:

akdeberg profile

Anik Khan


Convincing computers to do human tasks


Editor guide