DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

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

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)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await