Untouchable Data

Sometimes you need to " lock " an object so no one can accidentally ruin it.

1. Object.freeze(obj)

A complete freeze. You cannot add, delete, or change properties. The object becomes absolutely constant.

2. Object.seal(obj)

Prevents adding and deleting properties, but allows modifying existing ones.

3. Object.preventExtensions(obj)

Only prevents adding new properties.

Caution

These methods only work at the " shallow " level. If another object is nested inside, it can still be modified.

Note

The Object.isFrozen(obj) method helps check if an object is frozen.