Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Reflect.getOwnPropertyDescriptor — inspect an own property

Reflect.getOwnPropertyDescriptor(target, key) returns an own property's descriptor or undefined. It lets you inspect a property's value, accessors, and attributes without searching the prototype chain.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Reflect.getOwnPropertyDescriptor(target, key)

Reflect.getOwnPropertyDescriptor(target, key) describes only an own property of target, including a non-enumerable one. It returns a new descriptor object or undefined if the property is not an own property. An inherited property is not searched for along the prototype chain; an own property whose value is undefined still has a descriptor.

A data descriptor contains value, writable, enumerable, and configurable. An accessor descriptor contains get and set instead of value and writable; their values are functions or undefined. Inspecting an ordinary object's descriptor does not invoke its getter. Editing the returned descriptor does not itself redefine the property; use an operation such as Object.defineProperty for that.

target must be an object; every primitive value, including null and undefined, causes a TypeError. This differs from Object.getOwnPropertyDescriptor, which wraps primitive values other than null and undefined. The ToPropertyKey operation converts key to a property key. If key is an object, it first converts it to a primitive value, for example by calling its Symbol.toPrimitive method. If the primitive value is a symbol, it is kept as the key; otherwise, it is converted to a string.

Do not assume the operation is always side-effect-free: converting key can run user code, and a Proxy can invoke its getOwnPropertyDescriptor trap. Resulting exceptions propagate to the caller. The example demonstrates ignoring an inherited property and shows that changing descriptor.value does not change item.score.

Examples

const item = Object.create({ inherited: 1 });
Object.defineProperty(item, "score", {
  value: 42,
  writable: false,
  enumerable: true,
  configurable: true
});

const descriptor = Reflect.getOwnPropertyDescriptor(item, "score");
console.log(JSON.stringify(descriptor));
console.log(Reflect.getOwnPropertyDescriptor(item, "inherited"));
descriptor.value = 99;
console.log(item.score);

Result

{"value":42,"writable":false,"enumerable":true,"configurable":true}
undefined
42

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources