Recall & Review
beginner
What is the basic syntax to annotate an array of numbers in TypeScript?
You can annotate an array of numbers using <code>number[]</code>. For example: <code>let nums: number[] = [1, 2, 3];</code>Click to reveal answer
beginner
How do you annotate an array of strings using the generic Array type syntax?
Use the generic form <code>Array<string></code>. For example: <code>let names: Array<string> = ['Alice', 'Bob'];</code>Click to reveal answer
intermediate
Can you mix types in an array annotation? How?
Yes, by using a union type inside the array annotation. For example: <code>let mixed: (number | string)[] = [1, 'two', 3];</code>Click to reveal answer
beginner
What is the difference between
number[] and Array<number>?Both mean the same: an array of numbers.
number[] is shorthand, and Array<number> is the generic form. Use whichever you find clearer.Click to reveal answer
intermediate
How do you annotate a two-dimensional array of booleans?
You can write <code>boolean[][]</code> or <code>Array<Array<boolean>></code>. For example: <code>let grid: boolean[][] = [[true, false], [false, true]];</code>Click to reveal answer
Which of these is a correct TypeScript annotation for an array of strings?
✗ Incorrect
Both
string[] and Array<string> are valid ways to annotate an array of strings.How would you annotate an array that can hold numbers or strings?
✗ Incorrect
Both
(number | string)[] and Array<number | string> correctly annotate an array holding numbers or strings.What does
boolean[][] represent?✗ Incorrect
boolean[][] means an array where each element is an array of booleans.Which syntax is NOT valid for annotating an array of numbers?
✗ Incorrect
Array<number[]> means an array of arrays of numbers, not a simple array of numbers.What is the shorthand syntax for
Array<string>?✗ Incorrect
string[] is the shorthand for Array<string>.Explain how to annotate an array of mixed types in TypeScript.
Think about how to say 'this array can hold more than one type'.
You got /3 concepts.
Describe the difference and similarity between number[] and Array.
One is shorter, the other uses angled brackets.
You got /3 concepts.