Bird
0
0

You want to display a user's full name in Angular using interpolation, but the component only has firstName and lastName properties. Which template code correctly shows the full name?

hard📝 Application Q15 of 15
Angular - Templates and Data Binding
You want to display a user's full name in Angular using interpolation, but the component only has firstName and lastName properties. Which template code correctly shows the full name?
A<code>{{ firstName + ' ' + lastName }}</code>
B<code>{{ firstName & ' ' & lastName }}</code>
C<code>{{ firstName.concat(' ', lastName) }}</code>
D<code>{{ firstName | lastName }}</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand string concatenation in interpolation

    Angular interpolation supports JavaScript expressions, so you can use + to join strings.
  2. Step 2: Evaluate each option's correctness

    {{ firstName + ' ' + lastName }} uses + to join firstName, a space, and lastName correctly.
    {{ firstName & ' ' & lastName }} uses & which is invalid in JavaScript.
    {{ firstName.concat(' ', lastName) }} tries to call concat on firstName, which is valid JavaScript but may cause errors if firstName is undefined.
    {{ firstName | lastName }} uses a pipe which is for Angular pipes, not string concatenation.
  3. Final Answer:

    {{ firstName + ' ' + lastName }} -> Option A
  4. Quick Check:

    Use + to join strings inside {{ }} [OK]
Quick Trick: Use + to join strings inside {{ }} for full names [OK]
Common Mistakes:
  • Using & instead of + for concatenation
  • Misusing pipes for string joining
  • Calling methods that may not exist safely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes