Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Object.seal

Forbids adding and removing properties but lets existing ones change.

Available since: ES5

Syntax

Object.seal(obj)

Parameters

ParameterTypeDescription
objobjectThe object to seal.

Return value

objectThe same object, now sealed.

Examples

Changing works, adding and removing do not:

const user = Object.seal({ name: 'Anna' });
 
user.name = 'Oleg';
user.age = 30;
delete user.name;
 
console.log(user);

Output:

{
  "name": "Oleg"
}

Notes

The difference from Object.freeze(): a sealed object can be modified, only its shape — the set of properties — is fixed.

See also

In the tutorial

  • Immutability — Mutable and immutable data in JavaScript: object references, copying with spread, the toSorted and with methods, Object.freeze and structuredClone.

Thanks for reading!

Donate to the site — we work hard for you.