Promises Intro

Async Basics

Lesson 85
+30 XP
Step 1 of 5

What are Promises?

A Promise is an object that represents the eventual completion (or failure) of an asynchronous operation.

Key Concept: Think of a promise as an IOU - it promises to give you a value in the future, either successfully or with an error.

Promise States:

Pending

Initial state - the operation is still in progress

Fulfilled (Resolved)

The operation completed successfully

Rejected

The operation failed with an error

Why Use Promises?

  • Better than callbacks for handling async operations
  • Avoid "callback hell" (deeply nested callbacks)
  • Cleaner error handling
  • Chain multiple async operations together