Bird
0
0

Consider the following code:

medium📝 Predict Output Q4 of 15
Angular - Reactive Forms
Consider the following code:
const control = new FormControl('initial');
control.setValue('updated');
console.log(control.value);

What will be printed in the console?
Anull
B'initial'
Cundefined
D'updated'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze initial value

    The control is created with initial value 'initial'.
  2. Step 2: setValue changes the value

    The setValue method updates the control's value to 'updated'.
  3. Step 3: console.log outputs current value

    Logging control.value will output the updated value.
  4. Final Answer:

    'updated' -> Option D
  5. Quick Check:

    setValue updates FormControl value immediately [OK]
Quick Trick: setValue changes the value property instantly [OK]
Common Mistakes:
MISTAKES
  • Assuming initial value remains after setValue
  • Confusing value with control status
  • Expecting undefined if no value set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes