Skip to content
Justice Tech School

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

What does public in the constructor do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.