The blueprint
Lines 1 to 8 describe a bank account: the data each account holds and what it can do. A class is a blueprint. Writing it creates no account yet, just as a house plan is not a house.
Fields are the data inside each object. balance starts at 0, so TypeScript infers number; private hides it from code outside the class. public owner: string in the constructor is a shortcut that declares and fills an owner field.
Objects at run time
new Account("Ada") makes a fresh object from the blueprint and runs the constructor with "Ada". owner becomes "Ada" and balance starts at 0. The variable ada now refers to that object.
ada.deposit(50) calls the method on ada. Inside it, this means the object before the dot, so this.balance += amount adds 50 to ada's own balance: 0 becomes 50.
Line 11 deposits 25 more, so balance becomes 75. The method promises to return a number, and return this.balance hands back 75. console.log prints it.
The same blueprint builds bob. bob gets his own owner and his own balance, starting at 0, while ada keeps 75. Both objects share the one deposit method the class defines.
Checked, then erased
Line 13, outside the class, tries ada.balance = 1000; tsc stops it before anything runs: Property 'balance' is private and only accessible within class 'Account'. Only the class's own methods may change balance.
tsc writes JavaScript. Classes are part of JavaScript, so the class stays, but private and every type are erased. private is a compile-time check only; for privacy at run time, JavaScript has #balance fields.
What happens
;; step 1/8 · blueprint
account.ts, lines 1-8
> 1 class Account {
2 private balance = 0;
3 constructor(public owner: string) {}
4 deposit(amount: number): number {
5 this.balance += amount;
6 return this.balance;
7 }
> 8 }
class Account { ... } the blueprint
no object exists yet
TypeScript's private is a "soft" private: it is only enforced during type checking, so plain JavaScript (or bracket access like ada["balance"]) can still reach the field at run time. JavaScript's own #private fields are enforced at run time. The JavaScript shown is what tsc 5.9 writes with --target es2022. Older targets turn the class into a function with the method on Account.prototype; the program still prints 75.