JavaScriptMedium
What is Object.seal() for?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Object.seal() is used to prevent new properties from being added to an object and to mark all existing properties as non-configurable. This means you can still modify the values of existing properties, but you cannot delete them or add new ones. Doing so will throw errors in strict mode but fail silently in non-strict mode. In the following examples, you can uncomment the 'use strict' comment to see this.
js
// 'use strict'
const obj = { name: "John" };
Object.seal(obj);
obj.name = "Jane"; // Allowed
obj.age = 30; // Not allowed, throws an error in strict mode
delete obj.name; // Not allowed, throws an error in strict mode
console.log(obj); // { name: 'Jane } (unchanged)
