Skip to content
Justice Tech School

Static and Accessors

static belongs to the class. get and set make accessors.

Example
class C {
  static count = 0;
  private _v = 1;
  get v() { return this._v; }
  set v(n: number) { this._v = n; C.count++; }
}
const c = new C(); c.v = 5;
console.log(c.v, C.count);

Result

5 1

Exercise

Class property.

 count = 0

Quiz Test

Where does static live?

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