C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
| JavaScript Object.preventExtensions() MethodThe Object.preventExtensions() only prevents the addition of new properties from ever being added to an object (i.e., prevents future extensions to the object). This change is a permanent that means once an object has been made non-extensible, it cannot make extensible again. Syntax:
 Object.preventExtensions(obj) Parameter:
 obj: It is the object which should be made non-extensible. Return value:It returns the object being made non-extensible. Browser Support:
 
 Example 1
const uu = {};
Object.preventExtensions(uu);
console.log(
    Object.isExtensible(uu)
); 
Output: false Example 2
 const obj = {};
Object.preventExtensions(obj);
obj.o = 3;
console.log(
    obj.hasOwnProperty("o")
); 
Output: false Example 3
const t = {"p":3};
Object.preventExtensions(t);
delete t.p;
console.log ( t.hasOwnProperty ( "p" ) );
//expected output: false
Output: false 
Next TopicJavaScript Objects
 |