Bird
0
0

Identify the error in the following code snippet that uses the pipe method:

medium📝 Debug Q14 of 15
Angular - RxJS Operators
Identify the error in the following code snippet that uses the pipe method:
import { of } from 'rxjs';
import { map, filter } from 'rxjs/operators';

const obs$ = of(1, 2, 3);
obs$.pipe(
  map(x => x * 2),
  filter(x => x > 3)
).subscribe(console.log());
ACalling subscribe with parentheses executes immediately
BIncorrect import of operators
CMissing semicolon after pipe method
DUsing arrow functions inside pipe is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check subscribe usage

    The code calls subscribe(console.log()) which immediately executes console.log and passes its result (undefined) to subscribe.
  2. Step 2: Correct subscribe usage

    It should be subscribe(console.log) without parentheses to pass the function reference.
  3. Final Answer:

    Calling subscribe with parentheses executes immediately -> Option A
  4. Quick Check:

    subscribe needs function reference, not call = A [OK]
Quick Trick: Pass function to subscribe, don't call it [OK]
Common Mistakes:
MISTAKES
  • Calling subscribe with parentheses
  • Confusing operator imports
  • Thinking semicolon affects pipe chaining

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes