Bird
0
0

Given this code, what will be the final output in the console?

medium📝 component behavior Q5 of 15
Angular - RxJS Operators
Given this code, what will be the final output in the console?
import { of } from 'rxjs';
import { tap, filter } from 'rxjs/operators';

of(5, 10, 15).pipe(
  tap(x => console.log('Value:', x)),
  filter(x => x > 7),
  tap(x => console.log('Filtered Value:', x))
).subscribe();
AValue: 5 Filtered Value: 5 Value: 10 Filtered Value: 10 Value: 15 Filtered Value: 15
BValue: 5 Value: 10 Filtered Value: 10 Value: 15 Filtered Value: 15
CValue: 10 Value: 15
DFiltered Value: 10 Filtered Value: 15
Step-by-Step Solution
Solution:
  1. Step 1: Observe tap before filter

    The first tap logs all values: 5, 10, 15.
  2. Step 2: Apply filter and second tap

    Filter passes only values greater than 7 (10 and 15), which the second tap logs.
  3. Final Answer:

    Value: 5 Value: 10 Filtered Value: 10 Value: 15 Filtered Value: 15 -> Option B
  4. Quick Check:

    tap before and after filter logs all and filtered values [OK]
Quick Trick: tap before filter logs all; tap after logs filtered only [OK]
Common Mistakes:
MISTAKES
  • Expecting filtered values to appear in first tap
  • Ignoring filter effect on second tap
  • Assuming tap modifies values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes