Synchronous,Asynchronous in JavaScript



This content originally appeared on DEV Community and was authored by Kavya S

What is Synchronous?

In synchronous,each line of code executes line by line.
that means,each line of code waits for the previous one to execute

Example:

console.log("Hi")
console.log("Welcome")

Output
Hi
Welcome

What is Asynchronous?

  • In asynchronous,a task can be initiated and while waiting for it to complete, other task can be proceed.
  • It improves performance

Example:

console.log("Task1")
setTimeOut(()=>{
console.log("Task2")
},2000);
console.log("Task3")

Output
Task1
Task3
Task2


This content originally appeared on DEV Community and was authored by Kavya S