CKTIS / JavaScript
Reflect.defineProperty — defining properties with a boolean result
Reflect.defineProperty defines or changes an object's own property using a descriptor. It returns true or false, but does not guarantee exception-free execution.
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.defineProperty(target, propertyKey, attributes)Reflect.defineProperty(target, propertyKey, attributes) defines or changes an own property of target. The key is converted to a string or symbol, and attributes is a descriptor object. The method returns true when the operation succeeds, or false when the object's rules reject it.
A data descriptor uses value and writable; an accessor descriptor uses get and set. Both can contain enumerable and configurable. Data fields must not be mixed with accessor fields. When a property is created on an ordinary object, omitted flags default to false, and an omitted data value defaults to undefined. On an ordinary object, omitted fields remain unchanged when an existing property is updated without changing its kind. A configurable property can switch between data and accessor forms, and omitted enumerable and configurable fields keep their previous values. For example, converting a configurable data property to an accessor by specifying only get discards value and writable and sets the omitted set to undefined.
A Proxy's defineProperty trap receives a descriptor object in which omitted fields are still absent. The trap can create a property on the Proxy's underlying target with different attributes, subject to the Proxy invariants.
Unlike Object.defineProperty, which returns the object and throws TypeError when a definition is rejected, this method returns a boolean result. It is not exception-free: a non-object target, an invalid descriptor, or an exception during key conversion can interrupt the call. A Proxy's defineProperty trap can also throw.
For an ordinary object, adding a property to a non-extensible object or making a forbidden change to a non-configurable property returns false. In the example, the second definition cannot change id because writable and configurable are false; its value remains 7.
Examples
const item = {};
console.log(Reflect.defineProperty(item, "id", {
value: 7,
enumerable: true,
writable: false,
configurable: false
}));
console.log(Reflect.defineProperty(item, "id", { value: 8 }));
console.log(item.id);
console.log(Object.keys(item).join(","));Result
true false 7 id
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.