Bird
0
0

Given this Angular component snippet:

medium📝 state output Q4 of 15
Angular - Signals
Given this Angular component snippet:
export class CounterComponent {
  count = signal(0);
  increment() {
    this.count.set(this.count() + 1);
  }
}

What will be the value of count() after calling increment() twice?
AUndefined
B1
C0
D2
Step-by-Step Solution
Solution:
  1. Step 1: Understand initial value and increment

    Initial count is 0. Each increment adds 1 to current count.
  2. Step 2: Calculate after two increments

    After first call: 0 + 1 = 1; after second call: 1 + 1 = 2.
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    count after 2 increments = 2 [OK]
Quick Trick: Model signals update with .set(newValue) method [OK]
Common Mistakes:
  • Forgetting to call the signal as a function to get value
  • Assuming count does not change after increment
  • Confusing initial value with updated value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes