TheDeveloperBlog.com

Home | Contact Us

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

Javascript Object seal() Method

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

<< Back to JAVASCRIPT

JavaScript Object.seal() Method

The Object.seal() method of JavaScript seals an object which prevents new properties from being added to it and marks all existing properties as non-configurable. The object to be sealed is passed as an argument, and the method returns the object which has been sealed.

Syntax:

Object.seal(obj)

Parameter:

obj: It is the object which should be sealed.

Return value:

The Object.sealed() method returns the object which has been sealed.

Browser Support:

Chrome 6
Edge Yes
Firefox 4
Opera 12

Example 1

const obj1 = { property1: 'Marry'};
        const obj2 = Object.seal(obj1);
       // prevents other code from deleting properties of an object.
        obj2.property1 = 'carry';
        console.log(obj2.property1);

Output:

"carry"

Example 2

 const object1 = {
  property1: 29
};
Object.seal(object1);
// Prevents other code from deleting properties of an object.
object1.property1 =45;
console.log(object1.property1);
delete object1.property1;
   // cannot delete when sealed

Output:

 45

Example 3

const object1 = {
  property1: 42
};
Object.seal(object1);
object1.property1 = 45;
console.log(object1.property1);

delete object1.property1; // cannot delete when sealed
console.log(object1.property1);

const object2 = {
  property2: 45};
object2.property2 =67;
console.log(object2.property2);

Output:

45
45
67

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