Member-only story

Understanding Asynchronous JavaScript: Callbacks, Promises, and Async/Await

Ruchir Gupta
3 min readFeb 1, 2025

JavaScript is single-threaded, meaning it executes one operation at a time. However, real-world applications require handling multiple tasks concurrently, such as fetching data from an API, reading files, or querying a database. Asynchronous JavaScript enables non-blocking operations, improving performance and responsiveness.

In this article, we’ll explore three main ways to handle asynchronous operations: Callbacks, Promises, and Async/Await.

1. Understanding Synchronous vs Asynchronous JavaScript

Synchronous Code (Blocking)

JavaScript executes one line at a time. If a task takes too long (e.g., reading a file), the entire script is blocked.
Example:

console.log("Start");
for (let i = 0; i < 1000000000; i++) {} // Simulating a long task
console.log("End");

In this case, JavaScript waits for the loop to complete before moving to the next line.

Asynchronous Code (Non-Blocking)

JavaScript uses the Event Loop and callback queue to handle asynchronous operations efficiently.
Example:

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Ruchir Gupta
Ruchir Gupta

Written by Ruchir Gupta

Software Developer at Accenture India, Ex-Software Engineer at Roblox Corporation.

No responses yet

Write a response