← 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);
- A.undefined
- B.[Function: double]
- C.42
- 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 →