🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Classes, Modules, Map and Set: all 10 questions

Quiz: Classes, Modules, Map and Set · Question 1 of 10

What does this print? (code)

What does this print?

class Box {
  constructor(n) { this.n = n; }
  get double() { return this.n * 2; }
}
console.log(new Box(21).double);
  1. A.undefined
  2. B.[Function: double]
  3. C.42
  4. D.21
Answer & explanation

Correct answer: 42

A getter runs when the property is read, so double returns 21 * 2.

Can you get the rest right without peeking?

Take the timed Quiz: Classes, Modules, Map and Set quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →