MediumModern JS💻 Output Question

Proxy intercepts property access

💡

Hint

Proxy get trap intercepts all property reads. Use it for default values, validation, or virtual properties.

What does this output?

const handler = {
  get(target, prop) {
    return prop in target ? target[prop] : prop + ' not found';
  }
};
const obj = new Proxy({ x: 1, y: 2 }, handler);
console.log(obj.x);
console.log(obj.z);

Correct Output

1
z not found

Why this output?

Explanation: The get trap intercepts ALL property access. x exists → returns 1. z missing → returns "z not found".

Key Insight: Proxy get trap intercepts all property reads. Use it for default values, validation, or virtual properties.

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