JavaScript Object preventExtensions() method
prevents new properties from ever being added to an object

Object.preventExtensions() static method prevents new properties from ever being added to an object.

Object.preventExtensions() marks an object as no longer extensible, so that it will never have properties beyond the ones it had at the time it was marked as non-extensible.

Note that the properties of a non-extensible object, in general, may still be deleted.

Object.preventExtensions() only prevents addition of own properties. Properties can still be added to the object prototype.

Existing properties can still be modified or deleted, but new ones cannot be added.

There is no way to make an object extensible again once it has been made non-extensible.

syntax

Object.preventExtensions(obj)

obj The object which should be made non-extensible.

Attempting to add new properties to a non-extensible object will fail ↴

Object.preventExtensions() method will throw a TypeError in strict mode.

Object.preventExtensions() method will fail silently in non-strict mode.

To check if an object is extensible use isExtensible() method.

syntax description
prevent addition of new properties to myObject
Object.preventExtensions(myObject)