FrontendDeveloper.in

JavaScript question detail

What is the purpose of the seal method

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

const object = {
property: "Welcome JS world",
};
Object.seal(object);
object.property = "Welcome to object world";
console.log(Object.isSealed(object)); // true
delete object.property; // You cannot delete when sealed
console.log(object.property); //Welcome to object world
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399