Bird
0
0

Consider this Angular code migrating from observable to signal:

medium📝 state output Q5 of 15
Angular - Signals
Consider this Angular code migrating from observable to signal:
const userSignal = signal({name: 'Alice'});
userSignal.update(user => ({...user, name: 'Bob'}));
console.log(userSignal().name);
What is the console output?
ABob
BAlice
Cundefined
DAn error because update does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Understand signal update method

    update() takes a function to modify the current value immutably.
  2. Step 2: Apply update to change name

    The update changes name from 'Alice' to 'Bob'.
  3. Step 3: Read updated value

    Calling userSignal() returns the updated object with name: 'Bob'.
  4. Final Answer:

    Bob -> Option A
  5. Quick Check:

    Signal update changes value correctly = A [OK]
Quick Trick: Use update() to immutably change signal object values [OK]
Common Mistakes:
  • Expecting original value after update
  • Trying to mutate signal value directly
  • Assuming update method does not exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes