VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-object-preventextensions-method/

⇱ JavaScript Object preventExtensions() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Object preventExtensions() Method

Last Updated : 12 Jul, 2025

The Object.preventExtensions() method in JavaScript is a standard built-in object which prevents new properties from ever being added to an object. This method also prevents reassigning of the object's prototype.

Syntax: 

Object.preventExtensions( obj )

Parameters: This method accepts a single parameter as mentioned above and described below: 

  • obj: This parameter holds the object which must be made non-extensible.

Return value: This method returns the object after making it non-extensible.

Below examples illustrate the Object.preventExtensions() method in JavaScript:

Example 1: This example throws a type error as we cannot assign new properties to the object because Object.preventExtensions() method is used.

Output: 

TypeError: Cannot define property prop1, object is not extensible

Example 2: In this example, we will check if we have some properties of the object or not using the Object.hasOwnProperty() method with the Object.preventExtensions() method.

Output: 

true
false
false
false

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers: The browsers supported by Object.preventExtensions() method are listed below: 

  • Chrome 6 and above
  • Edge 12 and above
  • Firefox 4 and above
  • Opera 12 and above
  • safari 5.1 and above
Comment