Ask for a missing key."missing" was never defined on locked.
Result is undefined. No own property means no descriptor object.
Useful check. Compare the result with undefined before reading .value.
Compatibility
Browser & Runtime Support
Object.getOwnPropertyDescriptor() has been part of JavaScript since ES5 and is Baseline Widely available.
✓ Baseline · ES5
Object.getOwnPropertyDescriptor()
Supported in all modern browsers and Node.js. Also available in Internet Explorer 9+.
99%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Object.getOwnPropertyDescriptorExcellent
Bottom line: Use it to debug property flags or to copy descriptors when cloning objects carefully.
Frequently Asked Questions
It returns the descriptor for one own property, including value and flags like writable, enumerable, and configurable. If the property is missing, it returns undefined.
No. Only own properties are returned. Inherited keys give undefined even if you can read them through the prototype.
Properties created with obj.key = value are usually writable: true, enumerable: true, and configurable: true.
getOwnPropertyDescriptor reads one property. getOwnPropertyDescriptors returns descriptors for all own properties at once.
When the object has no own property with that name, including when the name exists only on the prototype.