Object.defineProperty() JavaScript

The Javascript Object defineProperty() method describes the behavioral attributes of the property. It is used to add a new property or change or modify a existing property directly to a specified object and returns the object.

Syntax:

Object.defineProperty(object, property, descriptor) 

Parameters:
object: It represents the object to which the new property will be defined.
property: It represents the property to be added or modified.
descriptor: It represents the descriptor of the property to be added or modified.

Return:
It returns the object with new or modified property.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
const obj = {};  
Object.defineProperty(a, ‘prop’, {value: 56} );  
obj.prop; 	 
document.write(obj.prop);    
</script>
</body>
</html>

Output:

56
Please Share