Recall & Review
beginner Click to reveal answer
What is an array in simple terms?
An array is like a row of boxes where each box can hold a value. You can find any box by its position number.
beginner Click to reveal answer
How do you declare an empty array of numbers in TypeScript?
You write: <code>let arr: number[] = [];</code> This means arr is an array that will hold numbers, and it starts empty.beginner Click to reveal answer
What does this code do? <br><code>let fruits: string[] = ['apple', 'banana', 'cherry'];</code>It creates an array named fruits that holds three strings: 'apple', 'banana', and 'cherry'.
intermediate Click to reveal answer
How can you declare an array with a fixed size but no values yet in TypeScript?
You can write: <code>let arr: number[] = new Array(5);</code> This creates an array with 5 empty slots.beginner Click to reveal answer
What happens if you try to put a string in a number array in TypeScript?
TypeScript will give an error because the array is only for numbers. It helps catch mistakes early.
How do you declare an array of strings named 'colors' with values 'red' and 'blue' in TypeScript?
✗ Incorrect
Option C correctly declares a string array with two values.
What is the initial length of
let nums = new Array(4);?✗ Incorrect
The array has 4 empty slots, so its length is 4.
Which of these is NOT a valid way to declare an empty number array in TypeScript?
✗ Incorrect
Option A is wrong because arr is declared as a number, not an array.
What type of error will TypeScript show if you add a string to a number array?
✗ Incorrect
TypeScript shows a type error because the value does not match the array type.
How do you access the first element of an array named 'items'?
✗ Incorrect
Square brackets with index 0 access the first element.
Explain how to declare and initialize an array of numbers with values 1, 2, and 3 in TypeScript.
Think about the syntax for arrays and how to specify types.
You got /3 concepts.
Describe what happens when you create an array with
new Array(5) in TypeScript.Consider the difference between size and content.
You got /3 concepts.
