Skip to content
Quiz · Classes and prototypes · lesson 3 of 12

Quiz — a getter

What does the program print?

JavaScript
class Rect {
    constructor(w, h) {
        this.w = w;
        this.h = h;
    }
    get area() {
        return this.w * this.h;
    }
}
const r = new Rect(2, 3);
r.w = 5;
console.log(r.area);

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way