Course contentsShow
← JavaScript
Lesson 2128 of 2,72344. Reactive PatternsFree lesson

Observables vs Promises

Key differences: observables support multiple values over time, are lazy, and can be cancelled.

Observables vs Promises

You'll learn the three key differences that set observables apart from promises in reactive programming.

The Core Distinction

Promises and observables both handle asynchronous operations, but they work fundamentally differently. A Promise represents a single future value—it resolves once and you're done. An Observable is like a stream that can emit multiple values over time, and it gives you fine-grained control over when and how that stream operates.

Three Critical Differences

1. Single vs Multiple Values

A promise resolves to one value (or rejects once). An observable can emit zero, one, or many values over its lifetime. Think of a promise as a single answer to a question, while an observable is like a subscription to updates.

2. Eager vs Lazy

Promises are eager—they start executing immediately when created. Observables are lazy—nothing happens until you subscribe. Create an observable that makes an HTTP request, and that request won't fire until someone actually subscribes to it.

3. Cancellation

Promises cannot be cancelled—once started, they run to completion. Observables can be cancelled by unsubscribing. This is crucial for cleaning up resources, stopping unnecessary work, or preventing memory leaks when components unmount.

Why It Matters

If you need to handle a button click stream, mouse movements, or WebSocket messages, promises fall short—they're built for one-shot operations. Observables shine when dealing with events, streams, and anything that produces values over time.

Key Takeaway: Observables differ from promises in three ways: they emit multiple values over time (not just one), they're lazy (don't execute until subscribed), and they're cancellable (via unsubscription).