MediumModern JS💻 Output Question

Getter and setter intercept access

💡

Hint

Getters/setters intercept property access and assignment. They look like properties but run code.

What does this output?

const obj = {
  _name: 'alice',
  get name()  { return this._name.toUpperCase(); },
  set name(v) { this._name = v.trim().toLowerCase(); }
};
console.log(obj.name);
obj.name = '  Bob  ';
console.log(obj.name);

Correct Output

ALICE
BOB

Why this output?

Explanation: Getter transforms to uppercase. Setter trims and lowercases. Both used with property syntax.

Key Insight: Getters/setters intercept property access and assignment. They look like properties but run code.

More Modern JS Output Questions

EasyDestructuring defaults apply only for undefinedEasyObject spread — later properties winMediumOptional chaining prevents TypeError on missing propertiesMediumNullish coalescing ?? vs OR ||

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz