- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Object freeze
JavaScript Objects
JavaScript Object freeze
Object.freezestops an object being changed after it is created.
const only stops the variable being reassigned, not the object being edited.
Object.freeze is what actually locks the contents.
Example
Example
javascript
const settings = Object.freeze({ theme: "dark" });
settings.theme = "light";
console.log(settings.theme);The assignment is ignored and the value stays dark.
In strict mode it would throw an error instead.
