Object.seal() method prevents additions or deletions of new properties.
Object.seal() method makes existing properties non-configurable.
syntax ↴
Object.seal(obj) ↴
obj The object which should be sealed.
A sealed object has a fixed set of properties: new properties cannot be added, existing properties cannot be removed, their enumerability and configurability cannot be changed, and its prototype cannot be re-assigned. Values of existing properties can still be changed as long as they are writable.
Attempting to delete or add properties to a sealed object, or to convert a data property to accessor or vice versa, will fail
Object.seal() method will throw a TypeError in strict mode
Object.seal() method will fail silently in non-strict mode.
Object.seal() returns the same object that was passed in.
Object.seal() method is used for sealing objects and arrays, to make an object immutable.
Object.seal() allows existing properties to be changed, as long as they are writable, unlike Object.freeze() method.
Object.seal() allows modification of existing properties, but does not permit addition or deletion of properties.
Object.freeze() on the other hand, prevents any modifications, additions, or deletions to properties.
Object.isSealed() method can be used to check if an object is sealed.
Object.seal(myObject)