- TypeScript have object-oriented programming features like  object,  classes, interfaces, etc.
- class consist of member variable and member function.
Below is code example:
1 2 3 4 5 6 7 8 9 10 11 12 |
class Greet { // creating class message = "hello world"; // member variable doGreet() { // member function console.log(this.message) } } let greetObj = new Greet(); // creating Greet class object greetObj.doGreet(); // calling class member function which is "doGreet" |
In above example, whenever new keyword is used , it invoke the constructor and create new object for Greet.
A constructor is a special function of the class that is responsible for initialising the variables of the class. in above example, it will initialise message with string “hello world”.