MediumPrototypes & Inheritance💻 Output Question

hasOwnProperty vs in operator

💡

Hint

hasOwnProperty = own only. in = entire chain. Use hasOwnProperty to distinguish instance vs inherited.

What does this output?

function Animal(name) { this.name = name; }
Animal.prototype.speak = function() { return this.name; };
const dog = new Animal('Rex');
console.log(dog.hasOwnProperty('name'));
console.log(dog.hasOwnProperty('speak'));
console.log('speak' in dog);

Correct Output

true
false
true

Why this output?

Explanation: name is own. speak is on the prototype — hasOwnProperty is false. in checks the whole chain — true.

Key Insight: hasOwnProperty = own only. in = entire chain. Use hasOwnProperty to distinguish instance vs inherited.

More Prototypes & Inheritance Output Questions

Easyinstanceof traverses the prototype chainMediumClass method override and instanceofMediumsuper calls the parent methodMediumObject.create sets prototype directly

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz