Bird
0
0

Consider the following Angular code:

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

What will be the output in the console?
A3 followed by 7
B7 followed by 3
C3 followed by 3
D7 followed by 7
Step-by-Step Solution
Solution:
  1. Step 1: Initial signal creation

    The signal score is initialized with the value 3.
  2. Step 2: First console.log

    Calling score() returns the current value, which is 3.
  3. Step 3: Updating the signal

    score.set(7) updates the signal's value to 7.
  4. Step 4: Second console.log

    Calling score() now returns 7.
  5. Final Answer:

    3 followed by 7 -> Option A
  6. Quick Check:

    Signal value updates correctly and is read by calling the signal function [OK]
Quick Trick: Calling signal() returns current value; set() updates it [OK]
Common Mistakes:
  • Assuming signal() returns the updated value before set() is called
  • Confusing the order of outputs
  • Using signal as a property instead of a function to read value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes