LearnFrenzy
Sign in Take a free test

Objects · Predict the Output · Question 11

A getter after a change Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
const circle = {
  r: 2,
  get area() { return 3 * this.r ** 2; },
};
circle.r = 3;
console.log(circle.area, typeof Object.getOwnPropertyDescriptor(circle, "area").get);
  • A 27 function Correct
  • B 12 function
  • C 27 number
  • D 12 undefined
Correct Answer: Option A

The getter runs on every read, so it uses the current r (3 × 9 = 27). The property's descriptor holds the get function instead of a value.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links