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 chainMediumhasOwnProperty vs in operatorMediumClass method override and instanceofMediumsuper calls the parent method

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz