DEV Community

Cover image for Understand synchronous Vs asynchronous code in Js
Elissa Twizeyimana
Elissa Twizeyimana

Posted on

Understand synchronous Vs asynchronous code in Js

Synchronous code runs step by step where each step has to wait for previous one to be executed.

Example:

console.log("Hello Friends");
console.log("Hello");
console.log("Nice to meet you");
Enter fullscreen mode Exit fullscreen mode

Here each line will execute then next until all finish.

Image description

But for asynchronous code it doesn't respect order stuff ,it get executed out of sequence.
Example:

console.log("Hello");
setTimeout(()=>console.log("Wait for 3 Second"),3000);
console.log("See you again");
Enter fullscreen mode Exit fullscreen mode

First line will execute and last while for second one it has to wait for 3seconds to it will execute last.

Image description
I'm grateful that you took the time to read my writing, and I hope it will help you develop. Let's collaborate to brighten the future. All of my primary profiles are available on My Github

Top comments (0)