DEV Community

Kavya S
Kavya S

Posted on

Synchronous,Asynchronous in JavaScript

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")
Enter fullscreen mode Exit fullscreen mode

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")
Enter fullscreen mode Exit fullscreen mode

Output
Task1
Task3
Task2

Top comments (0)