Skip to content
JavaScript·Intermediate·Coding·1 min read

What is the difference between own and inherited properties?

Short interview answer

Own properties are directly stored on the object and can be checked with Object.hasOwn. The in operator also considers the prototype chain. Object.keys enumerates own enumerable string-keyed properties only.

Example

JavaScript
const base = { inherited: 1 };const obj = Object.create(base);obj.own = 2;
'inherited' in obj;            // true  — walks the chainObject.hasOwn(obj, 'inherited'); // false — only this objectObject.keys(obj);              // ['own']

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Prototype chain

Related questions