$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · easy · #240

What is the output?

const o = {
  n: 1,
  get d() { return this.n * 2; }
};
o.n = 5;
console.log(o.d);
  1. 2
  2. 1
  3. 10
  4. NaN
A getter runs every time the property is read, so o.d is computed from the current n: 5 * 2 = 10.
Play Problem Solving ▸