JavaScriptMedium
What is Object.freeze() for?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Object.freeze() is used to make an object immutable. Once an object is frozen, you cannot add, remove, or modify its properties. This is useful for creating constants or ensuring that an object remains unchanged throughout the program.
js
const obj = { name: "John" };
Object.freeze(obj);
obj.name = "Doe"; // This will not change the name property
console.log(obj); // { name: 'John' }
