Bird
0
0

What will be logged to the console when this code runs?

medium📝 component behavior Q4 of 15
Angular - RxJS Operators
What will be logged to the console when this code runs?
import { of } from 'rxjs';
import { tap, map } from 'rxjs/operators';

of(1, 2, 3).pipe(
  tap(x => console.log('Before map:', x)),
  map(x => x * 2),
  tap(x => console.log('After map:', x))
).subscribe();
ABefore map: 2 After map: 2 Before map: 4 After map: 4 Before map: 6 After map: 6
BBefore map: 1 After map: 2 Before map: 2 After map: 4 Before map: 3 After map: 6
CBefore map: 1 Before map: 2 Before map: 3
DAfter map: 2 After map: 4 After map: 6
Step-by-Step Solution
Solution:
  1. Step 1: Trace the observable emissions

    The observable emits 1, 2, 3 in sequence.
  2. Step 2: Understand tap and map order

    The first tap logs original values before map doubles them. The second tap logs doubled values after map.
  3. Final Answer:

    Before map: 1 After map: 2 Before map: 2 After map: 4 Before map: 3 After map: 6 -> Option B
  4. Quick Check:

    tap logs before and after map = Before map: 1 After map: 2 Before map: 2 After map: 4 Before map: 3 After map: 6 [OK]
Quick Trick: tap logs values at its position in pipe chain [OK]
Common Mistakes:
MISTAKES
  • Assuming tap changes values
  • Ignoring order of operators
  • Expecting only one tap log per value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes