Recall & Review
beginner
What is a static member in a TypeScript class?
A static member is a property or method that belongs to the class itself, not to any instance of the class. You can access it using the class name without creating an object.Click to reveal answer
beginner
How do you declare a static property with a type in TypeScript?
Use the
static keyword before the property name and specify its type like this: static count: number;Click to reveal answer
intermediate
Can static methods access instance properties directly? Why or why not?
No, static methods cannot access instance properties directly because they belong to the class, not to any specific object. Instance properties need an object to exist.
Click to reveal answer
beginner
How do you call a static method in TypeScript?
You call it using the class name followed by the method name, like <code>ClassName.methodName()</code>, without creating an instance.Click to reveal answer
intermediate
What is the benefit of typing static members in TypeScript?
Typing static members helps catch errors early by ensuring the correct data types are used. It also improves code readability and helps tools provide better suggestions.
Click to reveal answer
How do you access a static property named
total in a class called Counter?✗ Incorrect
Static properties are accessed using the class name, so
Counter.total is correct.Which keyword is used to declare a static member in TypeScript?
✗ Incorrect
The
static keyword declares static members in a class.Can a static method access instance properties directly?
✗ Incorrect
Static methods cannot access instance properties directly because they do not belong to any object instance.
What happens if you try to access a static property through an instance?
✗ Incorrect
Accessing static properties through instances is not allowed and TypeScript will show an error.
Why is it useful to type static members in TypeScript?
✗ Incorrect
Typing static members helps catch mistakes early and makes the code easier to understand.
Explain what static members are in TypeScript and how you declare them with types.
Think about how static members belong to the class, not instances.
You got /3 concepts.
Describe how to access static members and why static methods cannot access instance properties directly.
Remember static means 'belonging to the class itself'.
You got /3 concepts.