Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaScriptprototype chain internalsSingle-choice MCQ

Why does Object.defineProperty behave differently from plain assignment when the prototype has a read-only (non-writable) data property of the same name?

const proto = {}; Object.defineProperty(proto, 'k', { value: 1, writable: false }); const obj = Object.create(proto); obj.k = 9; // line A (sloppy mode) Object.defineProperty(obj, 'k', { value: 9, writable: true }); // line B