JS Coding Questions Logo
JS Coding Questions
#196💼 Interview💻 Code

What is the purpose of the seal method

Advertisement

728x90

The Object.seal() method is used to seal an object, by preventing new properties from being added to it and marking all existing properties as non-configurable. But values of present properties can still be changed as long as they are writable. The next level of immutability would be the Object.freeze() method. Let's see the below example to understand more about seal() method

javascript
1const object = {
2  property: "Welcome JS world",
3  };
4
5Object.seal(object);
6
7object.property = "Welcome to object world";
8
9console.log(Object.isSealed(object)); // true
10
11delete object.property; // You cannot delete when sealed
12
13console.log(object.property); //Welcome to object world

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 26

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
196of476