# JS Tip of the Day: Sealing Objects

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-sealing-objects/643096>\
**Category:** web dev\
**Created:** [May 10, 2020, 8:23pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-sealing-objects/643096 "2020-05-10T20:23:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 10, 2020, 8:23pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-sealing-objects/643096/1 "2020-05-10T20:23:53Z")

</div>

**Sealing Objects**  
Level: Beginner

Just like you can prevent extensions in objects, you can also seal them. When an object is sealed, extensions are prevented and existing properties are set to non-configurable. Sealing is achieved with `Object.seal()`.

```javascript
let obj = { existing: true };
Object.seal(obj);
obj.prop = 'a new property'; // TypeError in strict mode
console.log(obj.prop); // undefined
delete obj.existing; // TypeError in strict mode
console.log(obj.existing); // true

```

Sealing an object locks the properties of an object in place so new ones can’t be added and existing ones can’t be removed. As with preventing extensions, it doesn’t apply to inheritance so a new property could be added (or removed) if inherited.

Once you seal an object, you can’t go back. But you can check to see if an object has been sealed using `Object.isSealed()`.

```javascript
let obj = {};
console.log(Object.isSealed(obj)); // false
Object.seal(obj);
console.log(Object.isSealed(obj)); // true

```

More info:

- [seal on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
