Bird
0
0

Identify the error in this code snippet using tap:

medium📝 Debug Q6 of 15
Angular - RxJS Operators
Identify the error in this code snippet using tap:
import { of } from 'rxjs';
import { tap } from 'rxjs/operators';

of(1, 2, 3).pipe(
  tap(console.log('Value'))
).subscribe();
AMissing import of map operator
Bpipe method is not called correctly
Ctap is called with the result of console.log instead of a function
Dsubscribe is missing a callback function
Step-by-Step Solution
Solution:
  1. Step 1: Analyze tap argument

    The code calls console.log('Value') immediately, passing its result (undefined) to tap.
  2. Step 2: Correct usage of tap

    tap expects a function to be passed, e.g. tap(value => console.log('Value', value)).
  3. Final Answer:

    tap is called with the result of console.log instead of a function -> Option C
  4. Quick Check:

    tap argument must be a function, not a function call [OK]
Quick Trick: Pass a function to tap, not the result of a function call [OK]
Common Mistakes:
MISTAKES
  • Calling console.log inside tap instead of passing a function
  • Ignoring parentheses in tap argument
  • Assuming tap modifies values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes