0
0
Typescriptprogramming~10 mins

Why TypeScript over JavaScript - 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 variable with a type in TypeScript.

Typescript
let age: [1] = 25;
Drag options to blanks, or click blank then click option'
Avar
Blet
Cstring
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using JavaScript keywords like 'var' or 'let' as types.
Using 'string' when the value is a number.
2fill in blank
medium

Complete the code to define a function parameter type in TypeScript.

Typescript
function greet(name: [1]) { console.log(`Hello, ${name}!`); }
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean for text data.
Using any without reason.
3fill in blank
hard

Fix the error by completing the type annotation for the array.

Typescript
let scores: [1] = [10, 20, 30];
Drag options to blanks, or click blank then click option'
Anumber[]
Bany
Cboolean[]
Dstring[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using string[] when the array has numbers.
Using boolean[] incorrectly.
4fill in blank
hard

Fill in the blank to create a typed object in TypeScript.

Typescript
let person: [1] = { name: 'Alice', age: 30 };
Drag options to blanks, or click blank then click option'
Aany
B{ name: number; age: string }
C{ name: string; age: number }
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the types of name and age.
Using any or object without specific types.
5fill in blank
hard

Fill all three blanks to create a typed function with parameters and return type.

Typescript
function add(a: [1], b: [2]): [3] { return a + b; }
Drag options to blanks, or click blank then click option'
Astring
Bnumber
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using string types for parameters or return value.
Using boolean as a type here.