Programming Fundamentals

Synchronous vs Asynchronous

Synchronous vs asynchronous code explained with JavaScript examples, and why async matters for I/O heavy applications.

Synchronous
Synchronous Execution
VS
Asynchronous
Asynchronous Execution
The short answer

Synchronous code runs one step at a time and blocks until each step finishes. Asynchronous code can start a task and move on, coming back to handle the result once it is ready.

Synchronous vs Asynchronous at a glance

SynchronousAsynchronous
Execution orderStrictly one step after anotherCan overlap, tasks run while waiting
BlockingBlocks the thread until the task finishesDoes not block, continues other work
Best forSimple, fast, CPU bound tasksSlow I/O like network calls or file reads
Code styleStraightforward top to bottomCallbacks, promises, or async and await
Failure handlingA thrown error stops the next lineErrors are handled separately, per task
ExampleA loop that sums an arrayFetching data from an API

When to use each

Choose Synchronous when

  • You are doing a quick calculation that does not involve waiting on anything external.
  • The order of operations must be strictly guaranteed, one after another.
  • The task is fast enough that blocking briefly has no noticeable cost.

Choose Asynchronous when

  • You are calling an API, reading a file, or querying a database.
  • You want the app to stay responsive while a slow task runs in the background.
  • You need to run multiple independent slow tasks at the same time instead of one after another.

The kitchen analogy

Synchronous code is like a cook who starts one dish, stands and watches it the whole time it cooks, then starts the next dish only once the first is fully done. Asynchronous code is like a cook who starts a dish, sets a timer, and works on something else while it cooks, coming back when the timer goes off.

// synchronous: blocks until the request finishes
const data = fetchDataSync();
console.log(data);
console.log('this runs after');

// asynchronous: does not block
fetchData().then(data => console.log(data));
console.log('this runs first, before data arrives');
In the interview

A strong point to make is that JavaScript itself is single threaded, so asynchronous code does not create new threads. Instead, slow work like network requests is handed off to the browser or Node runtime, and JavaScript picks the result back up later through the event loop.

Frequently asked questions

Does async mean multithreaded?

Not necessarily. In JavaScript, async code still runs on a single thread. The event loop lets slow operations happen in the background without blocking that thread, rather than using multiple threads.

What is a promise?

A promise represents a value that may not be available yet, and lets you attach code to run once that value resolves or fails, without blocking the rest of the program while you wait.

Is async always faster?

Not for CPU bound work. Async helps most when a task involves waiting, like a network call. For pure computation, synchronous code with no waiting is often just as fast or simpler.

Want more interview ready comparisons?

Browse every Synchronous vs Asynchronous style breakdown, or explore the full question library.

All comparisons Browse questions