![]() |
VOOZH | about |
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.
Object.defineProperties(obj, props) Example 1: In this example, we will define new properties to an object using the Object.defineProperties() method in JavaScript.
Output:
"geeksforgeeks"
undefined
Example 2: In this example, we will define new properties and modify some properties of an object using the Object.defineProperties() method in JavaScript.
Output:
"Hello"
"Geeks"
"Namaste" " And " "Stay Safe"
We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.
The browsers supported by Object.defineProperties() method are listed below:
The Object.defineProperties() method defines new or modifies existing properties directly on an object, returning the object.
Object.defineProperties() be used to freeze properties?You can create non-writable and non-configurable properties using
Object.defineProperties(), effectively making them immutable.
Object.defineProperties() handle deeply nested properties?
Object.defineProperties()only defines or modifies properties at the top level of the object. It does not traverse nested objects.
Object.defineProperties() interact with strict mode?In strict mode, attempting to define or modify properties in a way that violates property attributes will throw an error.
Object.defineProperties() method?
- Batch Property Definition: Defining multiple properties with specific attributes at once.
- Controlled Property Behavior: Customizing property behavior with attributes like
writable,enumerable, andconfigurable.- Implementing Getters and Setters: Creating dynamic properties with getter and setter functions.
- Updating Object Structures: Modifying and updating properties of existing objects efficiently.