1.

Explain the TypeScript class syntax.

Answer»

TypeScript fully supports classes. The TypeScript syntax for class declaration is similar to that of JavaScript, with the ADDED type support for the member declarations.

Here is a simple class that defines an Employee type.

class Employee { name: string; SALARY: number; constructor(name: string, salary: number) { this.name = name; this.salary = salary; } promote() : void { this.salary += 10000; }}

You can create an INSTANCE (or object) of a class by using the new keyword. 

// Create a new employeelet john = new Employee("John", 60000);console.log(john.salary); // 60000john.promote();console.log(john.salary); // 70000


Discussion

No Comment Found