JS Built-ins
← Object107 / 150
ObjectObject.sealbeginner

Object.seal() β€” cannot delete properties

πŸ“– Usage Example
// Prevent adding/removing properties but allow value changes
const obj = Object.seal({ x: 1 })
obj.x = 99     // allowed β€” value can change
delete obj.x   // silently ignored
obj.x          // β†’ 99

Use Object.seal() to prevent adding or deleting properties on an object while still allowing existing values to be updated.

Object.seal() β€” deletion blocked

After sealing, you cannot delete properties from the object (in sloppy mode, the delete silently fails; in strict mode, it throws).

Challenge: Demonstrate that property deletion silently fails on a sealed object.

πŸ’‘ Hints (1)
  • β€’ In sloppy mode, delete on sealed objects silently fails