01 / 05
Anyone outside can change it
With nothing written on it, a field can be read and written freely from outside. Handy, but nothing stops an odd value going in.
The balance below can be made -500 from outside. As far as TypeScript is concerned you only "put a number where a number goes", so it goes through.
class Savings { balance: number; constructor(balance: number) { this.balance = balance; }}const c = new Savings(1000);c.balance = -500;console.log(c.balance);Result
-500