JavaScript Object freeze() Method Last Updated : 12 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The Object.freeze() method is used to freeze an object. Freezing an object does not allow new properties to be added to the object and prevents removing or altering the existing properties. Object.freeze() preserves the enumerability, Configurability, writability, and prototype of the object. It returns the passed object and does not create a frozen copy.Syntax:Object.freeze(obj)Parameters:obj: It is the object which has to be frozen.Return Value:Object.freeze() returns the object that was passed to the function.Example 1: In this example, the object "obj2" has been assigned property from object "obj1", and the properties of "obj1" are frozen therefore new properties and values are prevented from being added to "obj2". JavaScript // Creating an object constructor and assigning values to it const obj1 = { property1: 'initial_data' }; // Creating a second object which will freeze // the properties of the first object const obj2 = Object.freeze(obj1); // Updating the properties of the frozen object obj2.property1 = 'new_data'; // Displaying the properties of the frozen object console.log(obj2.property1); Output : "initial_data"Example 2: In this example, the object "obj" has been assigned "prop: function" which has been later deleted since the object "obj wasn't frozen. After that, a new object "o" has been assigned the frozen values of "obj" which prevented it from further updations. JavaScript // Creating an object constructor and assigning values to it let obj = { prop: function () { }, name: 'adam' }; // Displaying the properties of the object created console.log(obj); // Updating the properties of the object obj.name = 'billy'; delete obj.prop; // Displaying the updated properties of the object console.log(obj); // Freezing the object using object.freeze() method let o = Object.freeze(obj); // Updating the properties of the frozen object obj.name = 'chris'; // Displaying the properties of the frozen object --> console.log(obj); Output : Object { prop: function () {}, name: "adam" } Object { name: "billy" } Object { name: "billy" }Applications:Object.freeze() is used for freezing objects and arrays, o make an object immutable.We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.Supported Browsers:Google ChromeMozillaOperaSafari Comment More infoAdvertise with us Next Article JavaScript Object getOwnPropertyDescriptor() Method S Shubrodeep Banerjee Follow Improve Article Tags : Misc JavaScript Web Technologies javascript-object JavaScript-Methods +1 More Practice Tags : Misc Similar Reads JavaScript Constructor Method A constructor in JavaScript is a special function used to create and initialize objects. It sets up object properties and is typically invoked using the new keyword. Constructors allow for the creation of multiple instances with similar properties and methods.In JavaScript, constructors can be defin 7 min read JavaScript Object assign() Method The Object.assign() method is used to copy the values and properties from one or more source objects to a target object. It invokes getters and setters since it uses both [[Get]] on the source and [[Set]] on the target.Syntax:Object.assign(target, ...sources);Parameters:target: It is the target obje 4 min read JavaScript Object create() Method JavaScript object.create() method is used to create a new object with the specified prototype object and properties. Object.create() method returns a new object with the specified prototype object and properties.Syntax:Object.create(prototype[, propertiesObject])Parameters:prototype: It is the proto 3 min read JavaScript Object defineProperty() Method The Object.defineProperty() method in JavaScript is a Standard built-in object which defines a new property directly on an object or it can also modify the existing property of an object and return the object. Syntax:Object.defineProperty(obj, prop, descriptor)Parameters:This method accepts three pa 3 min read JavaScript Object defineProperties() Method The Object.defineProperties() method in JavaScript is a standard built-in Object that defines a new or modifies existing properties directly on an object and it returns the object.Syntax:Object.defineProperties(obj, props) Parameters:Obj: This parameter holds the object on which the properties are g 2 min read JavaScript Object entries() Method The Object.entries() method in JavaScript is used to retrieve an array of an object's enumerable property [key, value] pairs. This method is particularly useful for transforming and iterating over objects in situations where array-like manipulation is needed.Syntax:Object.entries(obj);Parameters:obj 4 min read JavaScript Object freeze() Method The Object.freeze() method is used to freeze an object. Freezing an object does not allow new properties to be added to the object and prevents removing or altering the existing properties. Object.freeze() preserves the enumerability, Configurability, writability, and prototype of the object. It ret 3 min read JavaScript Object getOwnPropertyDescriptor() Method The Object.getOwnPropertyDescriptor() method in JavaScript is a standard built-in object that enables the full information on a property to be accessed and returns a property descriptor for the own property of a given object. Syntax: Object.getOwnPropertyDescriptor( obj, prop ) Parameters: This meth 2 min read JavaScript Object getOwnPropertyNames() Method The Object.getOwnPropertyNames() method in JavaScript is a standard built-in object which returns all properties that are present in a given object except for those symbol-based non-enumerable properties.Syntax:Object.getOwnPropertyNames(obj)Parameters:This method accepts a single parameter as menti 3 min read JavaScript Object getOwnPropertySymbols() Method The Object.getOwnPropertySymbols() method in JavaScript is a standard built-in object which returns an array of all symbol properties that are present in a given object. An empty array is returned until symbol properties are set on the object. Syntax: Object.getOwnPropertySymbols(obj) Parameters: ob 2 min read Like