TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Javascript Object preventExtensions() Method

Javascript Object preventExtensions() Method with example on javascript, object, getOwnPropertyDescriptor(), getOwnPropertyDescriptors(), defineProperties(), defineProperty(), entries(), freeze(), javascript tutorial, javascript array etc.

<< Back to JAVASCRIPT

JavaScript Object.preventExtensions() Method

The 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:

Chrome 6
Edge Yes
Firefox 4
Opera 12

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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf