Bird
0
0

What is the issue in this Angular RxJS code snippet?

medium📝 Debug Q6 of 15
Angular - RxJS Operators
What is the issue in this Angular RxJS code snippet?
import { of } from 'rxjs';
import { map } from 'rxjs/operators';

of(2, 4, 6).pipe(
  map(x => { x + 10; })
).subscribe(console.log);
AThe map operator is not imported correctly
BThe arrow function does not return a value explicitly
CThe observable should use from() instead of of()
DThe subscribe method is missing a callback
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the arrow function

    The arrow function uses curly braces but lacks a return statement, so it returns undefined implicitly.
  2. Step 2: Understand map behavior

    map expects a function that returns a transformed value; here, it returns undefined for each emission.
  3. Final Answer:

    The arrow function does not return a value explicitly -> Option B
  4. Quick Check:

    Arrow functions with braces need explicit return [OK]
Quick Trick: Use return with braces in arrow functions [OK]
Common Mistakes:
MISTAKES
  • Omitting return inside arrow functions with braces
  • Confusing map import errors with function errors
  • Assuming of() is incorrect for emitting values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes