MediumModern JS💻 Output Question

Computed property names with expressions

💡

Hint

Computed property names [expr] let you use dynamic keys and method names in object literals.

What does this output?

const key = 'name';
const obj = {
  [key]: 'Alice',
  [`get${key[0].toUpperCase() + key.slice(1)}`]() {
    return this[key];
  }
};
console.log(obj.name);
console.log(obj.getName());

Correct Output

Alice
Alice

Why this output?

Explanation: [key] = "name". The computed method name evaluates to "getName".

Key Insight: Computed property names [expr] let you use dynamic keys and method names in object literals.

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