Free preview.You're sampling one lesson — enroll free to unlock all 8 lessons and track your progress.
Enroll free lesson
Classes and Instances
Classes and Instances
In this lesson — part of Objects and Classes — you'll learn classes and instances in TypeScript and why it matters in real work.
Why it matters
Classes bundle data and behavior together — the core of object-oriented design.
Key ideas
- Classes and instances
- Fields and methods
- Constructors
- Encapsulation
In practice
Here's how it looks in idiomatic TypeScript:
class Counter {
count = 0;
increment(): void {
this.count++;
}
}
const c = new Counter();
c.increment();
console.log(c.count); // 1
TypeScript note: Class fields can be declared with initializers directly in the body, and TypeScript infers their types from the assigned value.
Try it yourself
Exercise: In TypeScript, write a Bank Account class with deposit and withdraw methods.
Recap
You now understand classes and instances and can apply it in TypeScript. Mark this lesson complete and continue to the next one.
