0
0
Typescriptprogramming~10 mins

Why typed arrays matter in Typescript - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a typed array of numbers.

Typescript
let numbers: [1] = [1, 2, 3, 4];
Drag options to blanks, or click blank then click option'
Anumber[]
Bstring[]
Cany[]
Dboolean[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using string[] instead of number[] causes type errors.
Using any[] loses the benefit of type safety.
2fill in blank
medium

Complete the code to declare a typed array of strings.

Typescript
const fruits: [1] = ['apple', 'banana', 'cherry'];
Drag options to blanks, or click blank then click option'
Aboolean[]
Bstring[]
Cnumber[]
Dany[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using number[] for string elements causes errors.
Using any[] removes type checking benefits.
3fill in blank
hard

Fix the error in the typed array declaration.

Typescript
let flags: [1] = [true, false, true];
Drag options to blanks, or click blank then click option'
Astring[]
Bnumber[]
Cboolean[]
Dany[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using string[] or number[] causes type mismatch errors.
Using any[] works but loses type safety.
4fill in blank
hard

Fill both blanks to declare a typed array and add a new element.

Typescript
let scores: [1] = [10, 20, 30];
scores.[2](40);
Drag options to blanks, or click blank then click option'
Anumber[]
Bpush
Cpop
Dstring[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using string[] for numbers causes errors.
Using pop removes elements instead of adding.
5fill in blank
hard

Fill all three blanks to declare a typed array, add an element, and access an element.

Typescript
let names: [1] = ['Alice', 'Bob'];
names.[2]('Carol');
const first: [3] = names[0];
Drag options to blanks, or click blank then click option'
Astring[]
Bpush
Cstring
Dnumber[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using number[] for string arrays causes errors.
Using pop instead of push removes elements.
Using number type for accessed element causes type mismatch.