Synchronous Vs Asynchronous JavaScript All You Need To Know

1.what is Synchronous Programming?

When the each instruction of code run one after another is called Synchronized programming.

JavaScript is Famous For Asynchronous Behavior But By Default JavaScript is not Asynchronous Because it is single threaded. Then how it act as Asynchronous well by using web api and callback Queue JavaScript can achieve Asynchronous behavior

2.What is Asynchronous Programming?

Well The Problem of Synchronous is that you have to wait all the instructions to be executed that's where asynchronous comes into play

Think of situations where you are fetching data from server if you don’t use asynchronous you have to wait until data is fetched all other instruction will not be executed until finished fetching .But using Asynchronous you don’t have to wait for fetching to completed. This the beauty of Asynchronous Programming

Take A Look At This Example:






Asynchronous output

take a look at the output task2 is not logged after task1.beacause of the Asynchronous nature of set timeout

So, That’s it hopefully it was helpful