Classes
Classes have typed properties and methods and a constructor.
Example
class Dog {
constructor(public name: string) {}
speak() { return this.name + " woofs"; }
}
console.log(new Dog("Rex").speak());Result
Rex woofs
Exercise
Parameter property.
constructor( name: string)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.