CKTIS / JavaScript
Reflect.preventExtensions — preventing object extension
Reflect.preventExtensions(target) prevents new own properties from being added to an object and returns a Boolean result. It does not freeze existing properties and can still throw exceptions.
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.preventExtensions(target)Reflect.preventExtensions(target) invokes the object's internal [[PreventExtensions]] operation. It returns true if the operation succeeds or false if it is rejected. The argument must be an object; a primitive value, including null, causes a TypeError. Exceptions from the internal operation propagate—a Boolean result does not mean exceptions are impossible.
For an ordinary object, success permanently prevents adding new own properties, including Symbol-keyed properties. Calling it again returns true. The prototype also cannot be changed to a different one. Existing properties can still be modified or deleted when their descriptors permit it; nested objects are not modified.
This is not equivalent to Object.seal or Object.freeze: the method does not change the configurable or writable attributes. Object.preventExtensions returns its argument on success and throws a TypeError when the operation returns false; it returns primitive values unchanged. Reflect.preventExtensions instead exposes the Boolean result and rejects primitives.
A Proxy can intercept the operation through its preventExtensions trap. The trap can refuse by returning false, but reporting success while the target remains extensible causes a TypeError. In the example, Reflect.set demonstrates a failed property addition without depending on strict mode.
Examples
const item = { count: 1 };
console.log(Reflect.preventExtensions(item));
console.log(Reflect.isExtensible(item));
console.log(Reflect.set(item, "extra", 10));
item.count = 2;
console.log(item.count);
console.log(Reflect.deleteProperty(item, "count"));
console.log(Reflect.has(item, "count"));Result
true false false 2 true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.