Bird
0
0

What will be the output of this Angular RxJS code?

medium📝 component behavior Q4 of 15
Angular - RxJS Operators
What will be the output of this Angular RxJS code?
import { of, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';

const source$ = throwError(() => new Error('Fail'));

source$.pipe(
  catchError(() => of('Recovered'))
).subscribe(value => console.log(value));
ANo output
BFail
CRecovered
Dundefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand throwError behavior

    The Observable emits an error immediately with message 'Fail'.
  2. Step 2: catchError intercepts and returns fallback

    The catchError replaces the error with an Observable emitting 'Recovered'.
  3. Final Answer:

    Recovered -> Option C
  4. Quick Check:

    catchError replaces error with fallback value [OK]
Quick Trick: catchError replaces error with fallback Observable output [OK]
Common Mistakes:
MISTAKES
  • Expecting original error message to print
  • Thinking error stops subscription without output
  • Confusing error object with emitted value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes