Exambodh - Practice Aptitude, Reasoning & GK Questions
Play Quiz
Start practice
≡One Liner Questions⌂Home?Play QuizAaArticles
General Knowledge›
Indian History›
Indian Polity›
Quantitative Aptitude›
Logical Reasoning›
Interview Practice›
General Science›
Computer Awareness›
View more categories (4)
Current Affairs›
Geography›
NCERT Solutions & Notes›
Static GK›
  1. Home
  2. |Articles
  3. |Callback vs Promises in JavaScript
←Back to Articles
JavascriptJavascript

Callback vs Promises in JavaScript

Javascript20 March 20265 min read

Share Article

Share on social media or copy your public link.

FacebookWhatsAppLinkedIn
JavaScript

Callback vs Promises in JavaScript

In JavaScript, many tasks take time to complete, such as API calls, reading files, or fetching database data. These are called asynchronous tasks. To manage them, JavaScript uses Callbacks and Promises. Both solve async problems, but promises provide a cleaner and more modern approach.

Why This Topic Matters

Callback and Promise are important JavaScript concepts. They are used in real projects and are also common in frontend interviews.

If you understand their difference, you will write cleaner async code and also understand why modern JavaScript prefers Promises and Async/Await.

1. What is a Callback?

Definition

A callback is a function that is passed as an argument to another function. It runs after the task is completed.

Simple Meaning

You tell a function: “First finish your work, then call this function.”

function fetchData(callback) {
  setTimeout(() => {
    callback("Data received");
  }, 1000);
}

fetchData((data) => {
  console.log(data);
});

How it works

The fetchData() function waits for 1 second. After that, it executes the callback function and passes the result.

Output

After 1 second, the console prints: Data received

2. Problem with Callbacks

Callbacks are fine for small tasks. But when multiple async operations depend on each other, the code becomes deeply nested and hard to understand.

loginUser(user, () => {
  getProfile(() => {
    getPosts(() => {
      console.log("All done");
    });
  });
});

What is Callback Hell?

This nested structure is called Callback Hell. It makes code difficult to read, debug, and maintain.

3. What is a Promise?

Definition

A Promise is an object that represents the future result of an asynchronous task. It gives either a success value or an error value later.

Simple Meaning

A promise says: “I will give you the result later — either success or failure.”

Promise States

Pending

The task is still running and the result is not ready yet.

Resolved

The task completed successfully and returned a value.

Rejected

The task failed and returned an error.

const fetchData = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("Data received");
  }, 1000);
});

fetchData
  .then((data) => {
    console.log(data);
  })
  .catch((error) => {
    console.log(error);
  });

How it works

The promise waits for 1 second and then calls resolve(). The .then() block receives the success result. If something fails, .catch() handles the error.

4. Promise Chaining

One big advantage of promises is that they allow multiple async tasks to be written in a cleaner sequence.

loginUser(user)
  .then(() => getProfile())
  .then(() => getPosts())
  .then(() => console.log("All done"))
  .catch((err) => console.log(err));

Why it looks better

Each step is written one after another, so the flow is easier to understand.

Error handling

If any step fails, the .catch() block handles the error in one place.

5. Callback vs Promise

Feature Callback Promise
Structure Can become nested Cleaner and chain-based
Readability Hard in complex code Easier to read
Error Handling Handled manually Handled with .catch()
Multiple Async Tasks Messy with nesting Better with chaining
Maintenance Harder in big projects Easier in big projects
Modern Usage Less preferred Widely used

6. When to Use Which?

Use Callback

  • For very small tasks
  • When only one step happens after completion
  • In older callback-based APIs

Use Promise

  • For multiple async operations
  • When better readability is needed
  • When easier error handling is important
  • As the base of async/await

7. Conclusion

Callbacks were one of the early ways to handle asynchronous code in JavaScript. They still work, but in complex situations they often create nested and hard-to-read code.

Promises solve this problem by making async code cleaner, more readable, and easier to manage. That is why modern JavaScript mostly prefers Promises and Async/Await.

Quick Summary

Callback is a function passed into another function to run later.

Promise is an object that represents a future success or failure result.

Callbacks can lead to Callback Hell.

Promises make async code cleaner and easier to maintain.

More In Javascript

Read more articles from the same category or open the full category archive directly.

Javascript

Javascript

JavaScript ES6+ Interview Questions & Concepts (Destructuring, Spread, Rest)

Modern JavaScript is not about writing more code, it's about writing smarter code.

React js

Javascript

JavaScript Basics Explained: Variables, Data Types & Functions with Examples

“Strong fundamentals in JavaScript make you a better React developer.”

Javascript

Javascript

JavaScript Arrays Explained with Examples Part 2 (Complete Beginner Guide)

Learn advanced JavaScript array methods with simple explanations and examples. This part covers flat, flatMap, findIndex, fill, copyWithin, Array.from, Array.isArray, and more.

Javascript
Javascript

JavaScript ES6+ Interview Questions & Concepts (Destructuring, Spread, Rest)

Javascript
React js

JavaScript Basics Explained: Variables, Data Types & Functions with Examples

Javascript
Javascript

JavaScript Arrays Explained with Examples Part 2 (Complete Beginner Guide)

View All Javascript Articles→

On This Page

Introduction

Recent Posts

Debounced Search Input

How to Build a Debounced Search Input in React.js

7 May 2026

React js

React 19 Features Explained with React 18 vs React 19 Comparison

7 May 2026

Javascript

React Interview Questions and Answers 2026 | SSR, CSR, Hooks, Virtual DOM

7 May 2026

Top AI cource

AI Courses for Software Developers in 2026: Best Course, Salary & Career Path

30 March 2026

Bharat Ratna Award

Bharat Ratna Award Winners List 1954 to 2024: History, Facts and Full List

26 March 2026

Awards and Honours

Nobel Prize 2025 Winners, History, Categories, Indian Winners & Important Facts (Hindi + English)

26 March 2026

Javascript

JavaScript ES6+ Interview Questions & Concepts (Destructuring, Spread, Rest)

21 March 2026

React js

JavaScript Basics Explained: Variables, Data Types & Functions with Examples

21 March 2026

Javascript

JavaScript Arrays Explained with Examples Part 2 (Complete Beginner Guide)

20 March 2026

Javascript

JavaScript Arrays Explained with Examples (Complete Beginner Guide)

20 March 2026

Exambodh

Exambodh helps students prepare for aptitude, reasoning, GK, and verbal exams with topic-wise practice questions, simple explanations, and structured learning.

Quick Links

HomePlay QuizArticlesAbout UsContactPrivacy PolicyDisclaimerCopyright PolicyTerms & Conditions

Study Hubs

Latest ArticlesGeneral KnowledgeQuantitative AptitudeLogical ReasoningComputer AwarenessCurrent Affairs

Popular Categories

General KnowledgeIndian HistoryIndian PolityQuantitative AptitudeLogical ReasoningInterview Practice
Explore:HomePlay QuizArticlesContact

Copyright 2026 Exambodh - aptitude, reasoning & verbal practice.