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.
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.
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).
Example
Let's assume that I have three sentences to log in console-
I would get output like this-
The output will be in sequence. JavaScript shows output in sequence.
Hence, if I were to change the sequence of the log-
the output sequence will also be changed-
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)
Top comments (0)