Bird
0
0

What is the issue with this Angular signal code?

medium📝 Debug Q6 of 15
Angular - Signals
What is the issue with this Angular signal code?
const count = signal(5);
count = 10;
console.log(count());
AThe signal function must be called with a string, not a number
BSignals are immutable; you cannot assign a new value directly to the signal variable
CYou must call count.set(10) instead of count = 10
DSignals cannot be logged using console.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand signal immutability

    Signal variables hold a reactive wrapper and cannot be reassigned directly.
  2. Step 2: Analyze the code

    Assigning count = 10 overwrites the signal reference, which is invalid.
  3. Final Answer:

    Signals are immutable; you cannot assign a new value directly to the signal variable -> Option B
  4. Quick Check:

    Do not reassign signal variables directly [OK]
Quick Trick: Never reassign signal variables directly [OK]
Common Mistakes:
  • Assigning new values directly to signal variables
  • Confusing signal() argument types
  • Thinking console.log cannot print signal values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes