Bird
0
0

Identify the mistake in this Angular state update:

medium📝 Debug Q6 of 15
Angular - State Management
Identify the mistake in this Angular state update:
const profile = signal({name: 'Alice'});
profile.set({name: 'Bob'});
profile().name = 'Charlie';
ASignals cannot hold objects as values
BCalling profile.set() twice causes a runtime error
CDirectly mutating the object returned by profile() does not update the signal
DThe initial signal value must be a string, not an object
Step-by-Step Solution
Solution:
  1. Step 1: Understand signal immutability

    Signals track changes via set(), not direct mutation.
  2. Step 2: Analyze code

    profile.set({name: 'Bob'}) correctly updates the signal.
  3. Step 3: Identify error

    Directly changing profile().name = 'Charlie' mutates the object but does not notify the signal.
  4. Final Answer:

    Directly mutating the object returned by profile() does not update the signal -> Option C
  5. Quick Check:

    Always use set() to update signals [OK]
Quick Trick: Never mutate signal value directly; use set() [OK]
Common Mistakes:
  • Mutating signal value directly expecting UI update
  • Believing signals cannot hold objects
  • Thinking multiple set() calls cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes