CKTIS / JavaScript
Object.getOwnPropertyDescriptor — inspect an own property
Object.getOwnPropertyDescriptor returns a description of an object's own property: its value or accessors and its attribute flags. It skips the prototype chain and returns undefined when the object has no such own property.
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
Object.getOwnPropertyDescriptor(obj, key)Object.getOwnPropertyDescriptor(obj, key) reads the descriptor of one own property, including a non-enumerable one. It does not search prototypes. The result is a new descriptor object, or undefined if the property is not directly on obj. An existing property whose value is undefined still has a descriptor.
A data property descriptor contains value, writable, enumerable, and configurable. An accessor property descriptor contains get and set instead of value and writable; a missing accessor is undefined. For an ordinary object, reading the descriptor does not invoke the getter. writable controls whether assignment can change the value, enumerable controls inclusion in enumeration, and configurable controls deletion or reconfiguration of the property.
Changing fields on the returned object does not change the original property. To apply a descriptor, use Object.defineProperty, subject to the existing property's restrictions. The descriptor is not a deep copy: an object stored in value remains the same reference.
key is converted to a property key: a string or symbol. Passing null or undefined as obj throws TypeError; other primitive values are wrapped as objects. For a Proxy, the operation can invoke the getOwnPropertyDescriptor trap, so it can have side effects or throw.
Examples
const obj = Object.create({ inherited: 1 });
Object.defineProperty(obj, "score", {
value: 42,
writable: false,
enumerable: true,
configurable: true
});
const descriptor = Object.getOwnPropertyDescriptor(obj, "score");
console.log(descriptor.value, descriptor.writable);
console.log(descriptor.enumerable, descriptor.configurable);
descriptor.value = 99;
console.log(obj.score);
console.log(Object.getOwnPropertyDescriptor(obj, "inherited"));Result
42 false true true 42 undefined
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.