Course contentsShow
← JavaScript
Lesson 1263 of 2,72329. PromisesFree lesson

What is a Promise?

A Promise is an object representing the eventual completion or failure of an asynchronous operation.

What is a Promise?

You'll learn: What a Promise is and why it exists in JavaScript.

The Core Idea

A Promise is a special object in JavaScript that represents the eventual completion (or failure) of an asynchronous operation. Think of it as a placeholder for a value you don't have yet, but will receive later.

When you start an async operation, instead of passing a callback function, you get back a Promise object immediately. This Promise acts like a receipt or tracking number—it doesn't contain your result right away, but it promises to give you the result (or an error) once the operation finishes.

A Real-World Analogy

Imagine ordering coffee at a café. The barista doesn't hand you coffee immediately—instead, you get a receipt with an order number. That receipt is your "promise" that you'll get coffee eventually. You can hold onto it, pass it to a friend, or wait for your number to be called. The receipt represents something that will resolve in the future.

Three States

A Promise exists in one of three states:

  • Pending: The operation hasn't finished yet
  • Fulfilled: The operation completed successfully with a result
  • Rejected: The operation failed with an error

Why Promises Matter

Before Promises, you saw callback hell—deeply nested callbacks that were hard to read and maintain. Promises provide a cleaner way to handle async operations without endless nesting. They're the foundation that makes modern async code manageable.

Key Takeaway: A Promise is an object that represents a future value from an asynchronous operation, acting as a placeholder that will eventually be fulfilled with a result or rejected with an error.