Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Angular - Signals
Identify the error in this code snippet:
const name = signal('Alice');
console.log(name);
name('Bob');
ACannot call signal variable as a function
BMissing parentheses when reading signal value
CCannot assign new value by calling signal as function
DSignal must be updated using name.set('Bob')
Step-by-Step Solution
Solution:
  1. Step 1: Check how signal values are read and updated

    Signals are read by calling them as functions: name(). To update, use name.set(newValue).
  2. Step 2: Identify the error in updating

    The code tries to update the signal by calling name('Bob'), which is invalid. The correct way is name.set('Bob').
  3. Final Answer:

    Signal must be updated using name.set('Bob') -> Option D
  4. Quick Check:

    Update signals with set() method [OK]
Quick Trick: Use set() to update signals, not calling them as functions [OK]
Common Mistakes:
  • Trying to update signal by calling it as a function
  • Forgetting parentheses when reading signal value
  • Confusing signal with normal variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes