Standard built-ins
Object.freeze()
Prevents extensions, makes own properties nonconfigurable, and makes own data properties nonwritable. Does not recursively freeze nested objects; accessor setters can still run.
Formal Syntax & Structure
javascript syntaxjavascript
Object.freeze(obj)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | Object | Target object. |
Return Value
Object
Same target (or unchanged primitive).
Working Example
Example Snippetjavascript
const o=Object.freeze({child:{n:1}});o.child.n=3;console.log(o.child.n);