Reflect.getOwnPropertyDescriptor(target, propertyKey) returns a descriptor: a small object that describes one property. It tells you the value and three flags: writable (can it be changed?), enumerable (is it listed in loops?) and configurable (can it be deleted or redefined?).
Only own properties are described, not the ones from the prototype. If the property does not exist, you get undefined. For a getter or setter, the descriptor has get and set instead of value and writable.
Remember
Reflect.getOwnPropertyDescriptor(target, key)
data property → { value, writable, enumerable, configurable }
accessor property → { get, set, enumerable, configurable }
not an own property → undefined
target must be an object, or TypeError
Syntax
Pass an object and a property name. Read the flags from the returned descriptor.
// ECMAScript 2015 (ES6)
Reflect.getOwnPropertyDescriptor(target, propertyKey)
// target : an object
// propertyKey : a string or a symbol
// returns : a descriptor object, or undefined
// throws : TypeError if target is not an object
Parameters
Parameter
Description
target
Required. The object to look at. If it is not an object, a TypeError is thrown.
propertyKey
Required. The name of the property: a string or a symbol.
Return Value
Return Value
Description
Descriptor object
For a data property: value, writable, enumerable, configurable. For a getter or setter: get, set, enumerable, configurable.
undefined
The object has no own property with that key.
TypeError (thrown)
target is not an object.
JavaScript Examples
Example 1 — Look at a Normal Property
Print the descriptor of a plain property as JSON, and read single parts of it.
Inherited: undefined
Property after editing the copy: 5
Reflect with a string: TypeError
Object with a string: 3
How It Works
Own only.shared lives on parent, so the child has no own descriptor for it and you get undefined.
A copy. Changing desc.value does not touch the object, so obj.count is still 5.
Stricter than Object.Object.getOwnPropertyDescriptor() wraps the string and answers 3, while Reflect throws a TypeError for any primitive.
Compatibility
Browser & Runtime Support
Reflect.getOwnPropertyDescriptor() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.
✓ ES2015 · Widely supported
Reflect.getOwnPropertyDescriptor()
Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.
ES2015Standard since
Google Chrome49+ · Desktop & Mobile
Full support
Microsoft Edge12+ · Chromium and legacy
Full support
Mozilla Firefox42+ · Desktop & Mobile
Full support
Apple Safari10+ · macOS & iOS
Full support
Opera36+ · Chromium based
Full support
Samsung InternetRecent versions · Android
Supported
Android WebView49+ · Chromium based
Supported
Node.js6+ · Server runtime
Supported
DenoSupported · JavaScript runtime
Supported
BunSupported · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
Reflect.getOwnPropertyDescriptor()Excellent
Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Reflect at all.
Frequently Asked Questions
It returns a descriptor object for an own property: value, writable, enumerable and configurable for a normal property, or get, set, enumerable and configurable for a getter or setter. If the property does not exist as an own property, it returns undefined.
writable: the value can be changed. enumerable: the property is listed by loops and Object.keys(). configurable: the property can be deleted and its flags can be changed.
No. Only own properties have a descriptor. For a property that comes from the prototype you get undefined. Walk up with Reflect.getPrototypeOf() if you need to look further.
No. The descriptor is a copy. To apply changes, pass the edited descriptor to Reflect.defineProperty().
The results are the same for objects. Object.getOwnPropertyDescriptor() turns primitives such as strings into objects first, while Reflect.getOwnPropertyDescriptor() throws a TypeError if the target is not an object.