All quizzesMedium
Operators & Subjects — Series 2
Preview — 3 of 10 questions
After one failed request, the search box stops working entirely. Why?
javascript
results$ = this.query$.pipe(
switchMap((q) => this.http.get<Hero[]>(`/api/search?q=${q}`)),
catchError(() => of([])),
);AcatchError must be the first operator in the chain
Bof([]) completes, and a completed inner stream completes the outer one
CThe error propagates up to the outer stream, and catchError there replaces the whole chain — including query$ — with of([]), which emits once and completes. Catching inside the switchMap keeps the outer stream alive
DswitchMap cannot be combined with catchError
A save button emits clicks; a form emits values. Which operator gives on click, take the current form value?
javascript
this.clicks$.pipe(
withLatestFrom(this.form.valueChanges),
map(([, value]) => value),
switchMap((value) => this.api.save(value)),
);AcombineLatest([clicks$, form$])
Bclicks$.pipe(withLatestFrom(form$)) — the click drives emission, the form only contributes its latest value
Cmerge(clicks$, form$)
Dzip(clicks$, form$)
What does each emit for a stream of 1, 2, 3 that then completes?
javascript
const state$ = actions$.pipe(scan((state, action) => reducer(state, action), initial));Ascan emits 6; reduce emits 1, 3, 6
BBoth emit 1, 3, 6
CBoth emit 6
Dscan emits the running total after each value — 1, 3, 6 — while reduce emits only the final 6, on completion
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.