DEV Community

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

Posted on

4 2

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

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more