Skip to main content
D
JavaScript
JavaScript Promises

JavaScript Promises

JavaScript promises handle asynchronous operations gracefully.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript promises act like real-life promises. The code says "I promise to get this data," and while it fetches the data in the background, the rest of the program keeps running. The promise eventually finishes and returns either the data or an error.

Example

Example
1/* this creates a promise */
2let myPromise = new Promise(function(resolve, reject) {
3  resolve("Data fetched!");
4});
5
6myPromise.then(result => console.log(result));

Key Points

  • A promise has three states: pending, fulfilled, or rejected.
  • The `then()` method handles successful results.
  • The `catch()` method handles errors and failures.
  • Promises solve the callback hell problem.

Up Next

Continue your journey with the next topic.

Go to JS Async/Await