0 of 3 saved

JavaScript5 min read

Classes

Read this chapter, write the program on this page, then pass a short check to open the next one.

Syntax sugar over prototypes.

Classes

class is cleaner syntax for constructor functions and prototypes. Under the hood, JS is still prototype-based.

  • constructor runs on new.
  • methods live on the prototype.
  • extends creates a subclass.
class Counter {
  constructor() {
    this.n = 0;
  }
  inc() {
    this.n += 1;
    return this.n;
  }
}
console.log(new Counter().inc());

After you read this chapter, use Write (when available) and Quiz on this page to lock it in.