C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.seal() MethodThe 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:
Example 1const 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 2const 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 3const 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
|