Bird
0
0

Consider the following Angular signal code:

medium📝 Predict Output Q4 of 15
Angular - Signals
Consider the following Angular signal code:
const score = signal(5);
score.set(score() * 2);
console.log(score());

What will be the output in the console?
A10
B5
CNaN
Dundefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand initial value

    The signal score is initialized with 5.
  2. Step 2: Evaluate update

    The set method updates score to score() * 2, which is 5 * 2 = 10.
  3. Step 3: Output value

    Logging score() prints 10.
  4. Final Answer:

    10 -> Option A
  5. Quick Check:

    Multiplication applied correctly [OK]
Quick Trick: Remember to call signal as a function to get value [OK]
Common Mistakes:
  • Forgetting to call the signal as a function to get its value
  • Assuming set adds instead of multiplies
  • Confusing signal object with its value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes