0
0
Angularframework~10 mins

Why TypeScript is required in Angular - 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 Angular using TypeScript.

Angular
let userName: [1] = 'Alice';
Drag options to blanks, or click blank then click option'
Anumber
Bvar
Clet
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'var' or 'let' as a type instead of a data type.
2fill in blank
medium

Complete the code to define a function with typed parameters in Angular using TypeScript.

Angular
function greet(name: [1]): string { return `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.
3fill in blank
hard

Fix the error in the Angular component class by adding the correct type annotation.

Angular
export class AppComponent { title: [1] = 'My App'; }
Drag options to blanks, or click blank then click option'
Astring
Bboolean
Cnumber
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or boolean instead of string.
4fill in blank
hard

Complete the code to create a typed Angular service method that returns a number.

Angular
getCount(): [1] { return this.count; }
Drag options to blanks, or click blank then click option'
Anumber
Bstring
C;
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as return type or missing semicolon.
5fill in blank
hard

Fill both blanks to define a typed Angular component property with an initial value.

Angular
export class UserComponent { userAge: [1] = [2]; }
Drag options to blanks, or click blank then click option'
Astring
B30
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using string type or adding quotes around the number.