RxJS & Observables Flashcards
7 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 7 RxJS & Observables flashcards as text
What does the `scan` operator do in RxJS?
Answer: Accumulates values over time like Array.reduce and emits each intermediate result
scan applies an accumulator function to each emission and emits the running total, similar to reduce but streaming intermediate results.
Which Angular service uses Observables under the hood to expose route parameter changes in a component?
Answer: ActivatedRoute
ActivatedRoute exposes params, queryParams, and data as Observables so components can react to navigation changes without re-creating the component.
What happens when you call `complete()` on a Subject?
Answer: All subscribers receive the completion notification and no further values can be emitted
Calling complete() sends the completion signal to all current subscribers and prevents any future next() or error() calls from being delivered.
Which operator should you use to emit a default value if the source Observable completes without emitting anything?
Answer: defaultIfEmpty
defaultIfEmpty emits a specified fallback value when the source completes without ever emitting, then completes itself.
In RxJS, what does `zip` emit compared to `combineLatest`?
Answer: zip pairs emissions by index and only emits when all sources have a new value at that index; combineLatest emits on any new value
zip combines the nth emission from each source into one array and waits for all sources to provide their nth value before emitting.
What is the purpose of the `distinctUntilChanged` operator?
Answer: Suppresses consecutive duplicate emissions, only emitting when the value changes
distinctUntilChanged compares each emission to the immediately preceding one and skips the emission if they are equal.
Which RxJS operator is used to perform side effects (like logging) without modifying the emitted values?
Answer: tap
tap (formerly named do) executes a side-effect function for each emission while passing the values through unchanged.