MediumPrototypes & Inheritance💻 Output Question

Own property shadows prototype property

💡

Hint

Own properties shadow prototype properties. The prototype is consulted only for missing own properties.

What does this output?

const proto = { x: 1, y: 2 };
const obj = Object.create(proto);
obj.x = 10;
console.log(obj.x);
console.log(obj.y);
console.log(obj.hasOwnProperty('y'));

Correct Output

10
2
false

Why this output?

Explanation: obj.x=10 shadows proto.x=1. y is not on obj, found on proto. hasOwnProperty("y") is false.

Key Insight: Own properties shadow prototype properties. The prototype is consulted only for missing own properties.

More Prototypes & Inheritance Output Questions

Easyinstanceof traverses the prototype chain→MediumhasOwnProperty vs in operator→MediumClass method override and instanceof→Mediumsuper calls the parent method→

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz