What is Object.defineProperties() in Javascript?
The Object.defineProperties() method defines new properties to an object or modifies the existing properties of an object.
The defineProperties() method is declared as follows:
Object.defineProperties( obj, prop)
obj: The object whose properties are defined.prop: An object whose keys represent the name of the properties to be set and whose values represent the descriptors of the properties to be set.
Property descriptor
The property descriptor can be used to:
- Change the value of the property, as shown below:
Object.defineProperties( obj, {prop: {value: "new Value"} } )
- Change the meta-data of the property, as shown below:
Object.defineProperties( obj, {prop: {writable: bool} } )
Object.defineProperties( obj, {prop: {enumerable: bool} } )
Object.defineProperties( obj, {prop: {configureable: bool} } )
Where bool is either true or false.
Return value
The defineProperties() method returns the object obj with the properties prop set.
Browser compatibility
The defineProperties() method is supported by the following browsers:
- Edge 12
- Firefox 4
- Google Chrome 5
- Internet Explorer 9
- Opera 11.6
- Safari 5
Code
Consider the code snippet below, which updates the existing properties using the defineProperties() method:
var Student = { name: 'Ali', rollNo:'12' }console.log(Student)Object.defineProperties(Student,{name: {value: 'Ali Ahmad', writable: false},rollNo: {value: '123'},})console.log(Student)
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved