πŸ”΄ Hard'this' BindingπŸ’» Output Question

Proxy get trap intercepts access

πŸ’‘

Hint

Proxy get trap intercepts ALL property access including inherited ones. "prop in target" checks own + prototype chain. Use hasOwnProperty for own-only check.

What does this output?

const handler = {
  get(target, prop) {
    return prop in target ? target[prop] : `'${prop}' not found`;
  }
};

const obj = new Proxy({ name: 'Alice', age: 25 }, handler);

console.log(obj.name);
console.log(obj.age);
console.log(obj.email);
console.log(obj.toString === Object.prototype.toString);

Correct Output

Alice
25
'email' not found
false

Why this output?

Explanation: name and age exist β†’ return normally. email doesn't exist β†’ trap returns message string. toString: "toString" is not "in" the plain obj (it's inherited) β€” so trap returns a string, not the function. obj.toString !== Object.prototype.toString.

Key Insight: Proxy get trap intercepts ALL property access including inherited ones. "prop in target" checks own + prototype chain. Use hasOwnProperty for own-only check.

More 'this' Binding Output Questions

🟑 MediumMethod extracted from objectβ†’πŸŸ‘ MediumArrow function thisβ†’πŸ”΄ Hardthis in nested functionβ†’πŸ”΄ Hardbind creates new functionβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz