Crypto Forem

Kavya S
Kavya S

Posted on

Synchronous,asynchronous in JavaScript

Synchronous
Each line of code is executed one after other and next line is not executed until the previous one has completed

console.log("hi")
console.log("welcome")
Enter fullscreen mode Exit fullscreen mode

Output

hi
welcome

Asynchronous
A task can be initiated and while waiting for to complete,other task can be proceed
It allows multiple task to run independently

console.log("task1")O
setTimeOut(()=>{
console.log("task2")
},2000);
console.log("task3")
Enter fullscreen mode Exit fullscreen mode

Output

task1
task3
task2

Top comments (0)