TypeScript. Object-oriented programming (OOP) (opens in new tab)
When we hear about OOP, what is the first thing that comes to mind? Classes! Basic structure Classes in TypeScript look pretty the same as in JavaScript only with specifying types. class Person { name: string; constructor(name: string) { this.name = name; } greet() { console.log(`Welcome, ${this.name}!`); } } const p1 = new Person("Mary"); p1.greet(); // Welcome, Mary! Access modifiers We can restrict or open access to specific properties or methods by using keywords: Private modifier The pri...
Read the original article