InterviewHubPRO
Section Overview
Q200

Question 200 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

38%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

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

javascript
  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