JavaScript Reflect.preventExtensions() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Static method

Definition

Reflect.preventExtensions(target) makes an object non-extensible: after the call, no new properties can be added to it. It returns true when this worked.

Existing properties are not touched. You can still read them, change them and delete them. This is the weakest of the three lock levels, below Object.seal() and Object.freeze().

Remember
Reflect.preventExtensions(target)

locks the object against NEW properties
returns true when it worked

Existing properties: still editable and deletable
It cannot be undone
target must be an object, or TypeError

Syntax

Pass an object. Use Reflect.isExtensible() to check the result.

JavaScript
const box = { width: 10 };

console.log(Reflect.preventExtensions(box));   // true
console.log(Reflect.isExtensible(box));        // false

box.height = 5;                                // ignored
console.log(box.height);                       // undefined
CallWhat it does
Reflect.preventExtensions(obj)Lock obj against new properties. Returns true.
Reflect.isExtensible(obj)Check the result: it now returns false.
Object.seal(obj)Also stops deleting and reconfiguring properties.
Object.freeze(obj)Also stops changing the values.

A standard JavaScript static method (ES2015) of the Reflect object: call it as Reflect.preventExtensions(). No import required. Siblings: Reflect.apply(), Reflect.construct(), Reflect.defineProperty(), Reflect.deleteProperty(), Reflect.get(), Reflect.getOwnPropertyDescriptor(), Reflect.getPrototypeOf(), Reflect.has(), Reflect.isExtensible(), Reflect.ownKeys(), Reflect.set(), Reflect.setPrototypeOf().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Reflect.preventExtensions(target)

// target : an object
// returns: true if it worked, false if not
// throws : TypeError if target is not an object

Parameters

ParameterDescription
targetRequired. The object to lock. If it is not an object, a TypeError is thrown.

Return Value

Return ValueDescription
trueThe object is now non-extensible (or it already was).
falseThe object could not be locked. This only happens with unusual objects such as some Proxy objects.
TypeError (thrown)target is not an object.

JavaScript Examples

Example 1 — Lock an Object Against New Properties

Lock an object, then try to add a property. In normal (sloppy) code the new property is silently ignored.

JavaScript
const user = { name: "Ann" };

console.log("Before: " + Reflect.isExtensible(user));
console.log("Result: " + Reflect.preventExtensions(user));
console.log("After: " + Reflect.isExtensible(user));

user.age = 30;
console.log("Has age: " + ("age" in user));
console.log("Name: " + user.name);
Try It Yourself

How It Works

  1. Check first. A new object is extensible, so the first line prints true.
  2. Lock it. Reflect.preventExtensions(user) returns true, and the object is now non-extensible.
  3. New property ignored. user.age = 30 has no effect, but the existing name is still there.

Example 2 — Existing Properties Can Still Change

Only new properties are blocked. Changing and deleting still work, which is the difference from seal() and freeze().

JavaScript
const config = { mode: "light", size: 1, debug: true };
Reflect.preventExtensions(config);

config.mode = "dark";
console.log("Changed: " + config.mode);

delete config.debug;
console.log("Keys left: " + Object.keys(config).join(", "));

console.log("Sealed: " + Object.isSealed(config));
console.log("Frozen: " + Object.isFrozen(config));

const frozen = Object.freeze({ mode: "light" });
frozen.mode = "dark";
console.log("Frozen value: " + frozen.mode);
Try It Yourself

How It Works

  1. Changes work. config.mode became "dark", because the property already existed.
  2. Deleting works. debug was removed, so only mode and size are left.
  3. Not sealed, not frozen. Both checks say false. A really frozen object keeps its old value, as the last line shows.

Example 3 — Strict Mode and Errors

In strict mode, adding a property to a locked object throws an error. A primitive target throws too. The catch blocks print the error type only.

JavaScript
function addColor(obj) {
  "use strict";
  obj.color = "red";
}

const car = { wheels: 4 };
Reflect.preventExtensions(car);

try {
  addColor(car);
} catch (err) {
  console.log("Adding in strict mode: " + err.name);
}

const result = Reflect.defineProperty(car, "color", { value: "red" });
console.log("defineProperty result: " + result);

try {
  Reflect.preventExtensions(5);
} catch (err) {
  console.log("Number target: " + err.name);
}
Try It Yourself

How It Works

  1. Strict mode complains. A function with "use strict" throws a TypeError when it tries to add a property to the locked car.
  2. Reflect answers with a boolean. Reflect.defineProperty() does not throw. It returns false because the object cannot grow.
  3. Only objects. A number cannot be locked, so Reflect.preventExtensions(5) throws a TypeError.

Browser & Runtime Support

Reflect.preventExtensions() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

Reflect.preventExtensions()

Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 49+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 42+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 36+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 49+ · Chromium based
Supported
Node.js 6+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
Reflect.preventExtensions() Excellent

Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Reflect at all.

Frequently Asked Questions

It makes an object non-extensible, so no new properties can be added to it. It returns true when it worked. Existing properties can still be changed and deleted.
preventExtensions() only blocks new properties. seal() also blocks deleting and reconfiguring existing properties. freeze() also blocks changing the values. Each step is stricter than the one before.
Object.preventExtensions() returns the object itself. Reflect.preventExtensions() returns true or false. Also, Object.preventExtensions(5) just returns 5, while Reflect.preventExtensions(5) throws a TypeError.
No. The change is permanent. If you need an object that can grow again, make a copy of the locked object, for example with the spread syntax { ...obj }.
In normal (sloppy) code it is silently ignored. In strict mode, and inside classes and modules, it throws a TypeError. Reflect.defineProperty() and Reflect.set() never throw for this. They return false.

Next: Reflect.set()

Learn how to change a property and get true or false instead of an error.

Reflect.set() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful