0
0
Typescriptprogramming~10 mins

Class property declarations in Typescript - Interactive Code Practice

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

Complete the code to declare a public property named name of type string.

Typescript
class Person {
  public [1]: string;
}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cprivate
Dconstructor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword like 'private' as the property name.
Forgetting to specify the property name.
2fill in blank
medium

Complete the code to declare a private property named age of type number.

Typescript
class Person {
  private [1]: number;
}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cpublic
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using public instead of private.
Using a wrong type like string instead of number.
3fill in blank
hard

Fix the error in the property declaration to make isActive a boolean property.

Typescript
class User {
  isActive: [1];
}
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cboolean
Dany
Attempts:
3 left
💡 Hint
Common Mistakes
Using string or number instead of boolean.
Omitting the type annotation.
4fill in blank
hard

Fill both blanks to declare a readonly property id of type number.

Typescript
class Product {
  [1] [2]: number;
}
Drag options to blanks, or click blank then click option'
Areadonly
Bprivate
Cid
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or public instead of readonly.
Swapping the order of property name and modifier.
5fill in blank
hard

Fill all three blanks to declare a protected property email of type string with an initial value.

Typescript
class Account {
  protected [1]: [2] = [3];
}
Drag options to blanks, or click blank then click option'
Aemail
Bstring
C'user@example.com'
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using number type instead of string.
Forgetting to add the initial value.
Using incorrect quotes for the string value.