Recall & Review
beginner
What is the generic array syntax in TypeScript?
It is a way to define arrays with a specific type using angle brackets, like
Array<Type>. For example, Array<number> means an array of numbers.Click to reveal answer
beginner
How do you declare an array of strings using generic array syntax?
You write <code>let names: Array<string> = ['Alice', 'Bob'];</code> which means <strong>names</strong> is an array that only holds strings.Click to reveal answer
beginner
What is the difference between
string[] and Array<string> in TypeScript?Both mean the same: an array of strings.
string[] is shorthand, and Array<string> is the generic syntax. You can use either based on preference.Click to reveal answer
intermediate
Can you use generic array syntax with custom types?
Yes! For example, if you have a type
Person, you can write Array<Person> to make an array of Person objects.Click to reveal answer
intermediate
Why use generic array syntax instead of the shorthand?
Generic syntax is clearer when working with complex types or nested generics. It helps readability and consistency in some cases.
Click to reveal answer
Which of the following declares an array of numbers using generic array syntax?
✗ Incorrect
Option D correctly uses
Array<number> to declare an array of numbers.What does
Array<string> mean in TypeScript?✗ Incorrect
Array<string> means an array that holds only strings.Which is the shorthand for
Array<boolean>?✗ Incorrect
boolean[] is the shorthand for Array<boolean>.Can you use generic array syntax with a custom type
Car?✗ Incorrect
Generic array syntax works with any type, including custom types like
Car.Why might you choose
Array<Type> over Type[]?✗ Incorrect
Generic syntax can be clearer and easier to read with complex or nested types.
Explain how to declare an array of numbers using generic array syntax in TypeScript.
Think about how you tell TypeScript what type the array holds using < and >.
You got /4 concepts.
Describe the difference and similarity between
string[] and Array<string>.Both are ways to say 'array of strings' but look different.
You got /3 concepts.