Bird
0
0

Given the component property user = null;, what will be the output of this Angular template snippet?

medium📝 component behavior Q13 of 15
Angular - Templates and Data Binding
Given the component property user = null;, what will be the output of this Angular template snippet?
{{ user?.name || 'Guest' }}
Aundefined
BGuest
Cnull
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate safe navigation on null

    Since user is null, user?.name safely returns undefined without error.
  2. Step 2: Apply the logical OR operator

    The expression undefined || 'Guest' evaluates to 'Guest' because undefined is falsy.
  3. Final Answer:

    Guest -> Option B
  4. Quick Check:

    Safe navigation returns undefined, fallback used [OK]
Quick Trick: Safe navigation returns undefined, use || for fallback [OK]
Common Mistakes:
  • Expecting an error on null access
  • Thinking output is 'null' string
  • Ignoring fallback with || operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes