0 votes
in JavaScript by
What is the purpose of seal method in Javascript?

1 Answer

0 votes
by

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. 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

Related questions

0 votes
asked Oct 6, 2023 in JavaScript by GeorgeBell
0 votes
asked Oct 3, 2023 in JavaScript by AdilsonLima
...