JavaScript Object.preventExtensions() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

Object.preventExtensions(obj) marks an object so you cannot add new own properties. Existing properties can still be changed or deleted (unless you sealed or froze them).

It returns the same object. Check with Object.isExtensible(obj). This is the weakest of the three locks: preventExtensions < seal < freeze.

Syntax

Call Object.preventExtensions() like this. Start with this line.

JavaScript
Object.preventExtensions(obj)
CallWhat it does
Object.preventExtensions(obj)Makes obj non-extensible and returns it.
Object.isExtensible(obj)Returns false after preventExtensions.
obj.newKey = 1Fails quietly in non-strict mode; throws in strict mode.

Pass the object to lock against new properties. The call returns that same object.

Library declarations
JavaScript
Object.preventExtensions(obj)
JavaScript
Object.preventExtensions<T>(o: T): T

Parameters

ParameterDescription
objRequired. The object that should no longer accept new own properties.

Return Value

Return ValueDescription
objectThe same object you passed in, now non-extensible.

JavaScript Examples

Stop Adding Properties

Prevent extensions, then try to add a new key.

JavaScript
var car = { brand: "Tata" };

Object.preventExtensions(car);
console.log(Object.isExtensible(car));

car.brand = "Mahindra";
car.year = 2024;

console.log(car.brand);
console.log(car.year);
Try It Yourself

How It Works

  1. No longer extensible. isExtensible becomes false.
  2. Existing writes work. Updating brand still succeeds.
  3. New key ignored. In non-strict mode, year is not added, so it prints undefined.

You Can Still Delete Properties

Unlike seal, preventExtensions does not block delete.

JavaScript
var bag = { color: "blue", size: "M" };
Object.preventExtensions(bag);

delete bag.size;
console.log(bag);
console.log(Object.keys(bag));
Try It Yourself

How It Works

  1. Delete succeeds. size is removed even though the object is non-extensible.
  2. Keys update. Object.keys now shows only color.
  3. Need stronger lock? Use Object.seal if deletes should also be blocked.

Compare preventExtensions, seal, and freeze

Run the same three actions on each lock: change x, add y, delete x.

JavaScript
function tryAll(label, obj) {
  obj.x = 2;
  obj.y = 9;
  delete obj.x;
  console.log(label, obj);
}

var a = { x: 1 };
Object.preventExtensions(a);
tryAll("prevent", a);

var b = { x: 1 };
Object.seal(b);
tryAll("seal", b);

var c = { x: 1 };
Object.freeze(c);
tryAll("freeze", c);
Try It Yourself

How It Works

  1. preventExtensions. Change and delete both work; adding y fails. After deleting x, the object is empty: {}.
  2. seal. Changing x works, but add and delete fail, so you keep { x: 2 }.
  3. freeze. Change, add, and delete all fail, so the object stays { x: 1 }.

Browser & Runtime Support

Object.preventExtensions() is part of ES5 and works in all modern browsers and Node.js.

✓ ES5 · Baseline

Object.preventExtensions()

Supported across current browsers and runtimes. Use with Object.isExtensible() to check.

100% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Object.preventExtensions Excellent

Bottom line: Safe everywhere modern JavaScript runs. Prefer seal or freeze when you also need to block deletes or value changes.

Frequently Asked Questions

It stops new own properties from being added. Existing properties can still change or be deleted.
seal also blocks removing properties and makes them non-configurable. preventExtensions only blocks adding.
freeze also blocks changing values. preventExtensions does not.
No. Once non-extensible, an object stays that way. Create a new object if you need a mutable copy.
Call Object.isExtensible(obj). It returns false after preventExtensions, seal, or freeze.

Next: seal()

Lock an object’s keys but allow value updates.

seal() 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.

8 people found this page helpful