RxJS & Observables Flashcards
6 cards from real Angular Web Framework practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 RxJS & Observables flashcards as text
What is an Observable in Angular/RxJS?
Answer: A lazy collection of values that can emit multiple items over time and be subscribed to
An Observable represents a stream of values over time, producing data only when subscribed to (lazy evaluation), and can emit zero or more values before completing or erroring.
What is the difference between a Subject and an Observable?
Answer: A Subject is both an Observable and an Observer — it can emit values and be subscribed to
A Subject is multicast (multiple subscribers), can manually emit values using next(), and acts as both an Observable (can be subscribed to) and an Observer (can receive values).
What does the pipe() method do in RxJS?
Answer: Chains multiple operators together to transform, filter, or combine Observable streams
The pipe() method allows composing multiple RxJS operators (map, filter, switchMap, etc.) into a processing pipeline that transforms the Observable stream.
What is the switchMap operator used for?
Answer: To cancel the previous inner Observable and subscribe to a new one when the source emits
switchMap maps each source value to an inner Observable, automatically unsubscribing from the previous inner Observable when a new source value arrives, preventing stale requests.
Why is it important to unsubscribe from Observables?
Answer: To prevent memory leaks by cleaning up subscriptions that are no longer needed
Failing to unsubscribe from Observables (especially those that don't complete naturally) creates memory leaks, as the subscription continues holding references and processing emissions.
What is the async pipe in Angular templates?
Answer: A pipe that automatically subscribes to an Observable, displays the latest value, and unsubscribes on destroy
The async pipe subscribes to an Observable or Promise in the template, renders the latest emitted value, and automatically unsubscribes when the component is destroyed, preventing memory leaks.