Bird
0
0

What will be the output of this code?

medium📝 state output Q5 of 15
Angular - State Management
What will be the output of this code?
const name = signal('Alice');
const greeting = computed(() => `Hello, ${name()}`);
name.set('Bob');
console.log(greeting());
AHello, Alice
BError: greeting is not a function
CHello, Bob
DHello, undefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand computed signals

    greeting depends on name() and updates when name changes.
  2. Step 2: Track value changes

    After name.set('Bob'), greeting() returns 'Hello, Bob'.
  3. Final Answer:

    Hello, Bob -> Option C
  4. Quick Check:

    Computed updates with dependencies = D [OK]
Quick Trick: Computed signals auto-update when dependencies change [OK]
Common Mistakes:
  • Expecting greeting to stay 'Hello, Alice'
  • Not calling greeting as a function
  • Confusing computed with static variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes