JS: Reflect.getOwnPropertyDescriptor

By Xah Lee. Date: . Last updated: .

New in ES2015.

Reflect.getOwnPropertyDescriptor ( obj, key )

Return the property attributes. If the property doesn't exist, returns undefined.

[see JS: Property Attributes, writable, enumerable, configurable]

The return value is a Property Descriptor.

[see JS: Property Descriptor]

If obj is not object, throw a TypeError exception.

const hh = {p:4};

console.log (
 Reflect.getOwnPropertyDescriptor ( hh , "p" )
// { value: 4, writable: true, enumerable: true, configurable: true }

// non-exist key
console.log (
 Reflect.getOwnPropertyDescriptor ( hh , "yyy" ) === undefined
// true

Object.getOwnPropertyDescriptor vs Reflect.getOwnPropertyDescriptor?

What's the difference?

Object.getOwnPropertyDescriptor ( obj, key ) will first convert obj to object.

[see JS: Object.getOwnPropertyDescriptor]


ECMAScript® 2016 Language Specification#sec-reflect.getownpropertydescriptor

back to JS: Reflect

JS Object Property Topic

  1. JS: Property Overview
  2. JS: Property Key
  3. JS: Property Dot Notation / Bracket Notation
  4. JS: Create/Delete Property
  5. JS: Get Property, Set Property
  6. JS: Check Property Existence
  7. JS: Access Property
  8. JS: Property Attributes, writable, enumerable, configurable
  9. JS: Getter/Setter Properties
  10. JS: Property Descriptor
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.