Complete the code to declare a read-only array of numbers.
const numbers: [1] = [1, 2, 3];
number[] allows modification.const inside the type is incorrect.Using readonly number[] declares an array that cannot be changed after creation.
Complete the code to prevent modification of the array elements.
function printFirst(numbers: [1]) { console.log(numbers[0]); }
number[] allows modification inside the function.const in the type is invalid.Using readonly number[] ensures the function cannot modify the array.
Fix the error by completing the code to assign a read-only array.
const arr: readonly string[] = ['a', 'b']; // Error: Cannot assign to 'arr' arr = [1];
new Array() to assign a new array.You cannot assign a new array to a read-only variable. Assigning arr to itself avoids the error.
Fill both blanks to create a read-only array and access its first element.
const fruits: [1] = ['apple', 'banana']; const firstFruit: string = fruits[2];
number as the type for the array..length.The array is declared as readonly string[] and the first element is accessed with [0].
Fill all three blanks to declare a read-only array, map its elements, and prevent modification.
const letters: [1] = ['x', 'y', 'z']; const upperLetters = letters.map(letter => letter.[2]()); // Error if uncommented: letters.[3]('a');
string[].toUpperCase.push on a read-only array.The array is read-only (readonly string[]), mapping uses toUpperCase(), and push is not allowed on read-only arrays.