Bird
0
0

How should you correctly type annotate a property tags in an Angular component to hold an array of strings?

hard📝 Application Q8 of 15
Angular - TypeScript in Angular
How should you correctly type annotate a property tags in an Angular component to hold an array of strings?
Atags: [string] = [];
Btags: Array = [''];
Ctags: string[] = [];
Dtags: string = [];
Step-by-Step Solution
Solution:
  1. Step 1: Understand Array Type Annotation

    In TypeScript, an array of strings is annotated as string[] or Array<string>.
  2. Step 2: Check Initialization

    Initializing with an empty array [] is valid.
  3. Final Answer:

    tags: string[] = []; -> Option C
  4. Quick Check:

    Use string[] for string arrays [OK]
Quick Trick: Use string[] for arrays of strings [OK]
Common Mistakes:
  • Using Array without generic type
  • Using tuple syntax incorrectly
  • Assigning array to a string type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes