Bird
0
0

Which of the following is the correct way to create a BehaviorSubject with an initial value of 0?

easy📝 Syntax Q3 of 15
Angular - State Management
Which of the following is the correct way to create a BehaviorSubject with an initial value of 0?
Aconst store$ = new BehaviorSubject(); store$.next(0);
Bconst store$ = new BehaviorSubject(0);
Cconst store$ = BehaviorSubject.create(0);
Dconst store$ = BehaviorSubject(0);
Step-by-Step Solution
Solution:
  1. Step 1: Check BehaviorSubject constructor usage

    The constructor requires an initial value passed directly.
  2. Step 2: Validate options

    Only new BehaviorSubject(0); correctly creates the instance with initial value 0.
  3. Final Answer:

    const store$ = new BehaviorSubject(0); -> Option B
  4. Quick Check:

    BehaviorSubject creation with initial value = C [OK]
Quick Trick: Always use new BehaviorSubject(initialValue) to create it [OK]
Common Mistakes:
  • Calling BehaviorSubject without new
  • Using create() method which doesn't exist
  • Creating without initial value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes