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 an existing property directly to a specified object and returns the object.


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 a new or modified property.


<!DOCTYPE html>
const obj = {};
Object.defineProperty(a, ‘prop’, {value: 56} );
Please follow and like us:
Content Protection by DMCA.com