Bird
0
0

Identify the error in this Angular signal code:

medium📝 Debug Q14 of 15
Angular - State Management
Identify the error in this Angular signal code:
const name = signal('Alice');
name.update(name + ' Smith');
AIncorrect initial value type for signal
BMissing parentheses when calling signal()
CUsing update() with a string instead of a function
DUsing set() instead of update()
Step-by-Step Solution
Solution:
  1. Step 1: Understand update() usage

    update() expects a function that receives the current value and returns the new value.
  2. Step 2: Analyze the code's argument to update()

    The code passes name + ' Smith' which is a string, not a function, causing an error.
  3. Final Answer:

    Using update() with a string instead of a function -> Option C
  4. Quick Check:

    update() needs a function argument [OK]
Quick Trick: Pass a function to update(), not a direct value [OK]
Common Mistakes:
  • Passing value directly to update()
  • Confusing set() and update() usage
  • Ignoring function argument requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes