JavaScript Object.defineProperty() Method

The Object.defineProperty() method defines a new property directly on an object and returns the object. To change the flags, we can use Object.defineProperty. We cannot change it back, because define property doesn?t work on non-configurable properties.

Syntax:

Parameter

Obj: The Object on which to define the property.

Prop: The name of a property to be defined or modified.

Descriptor: The descriptor for the property being defined or modified.

Return:

This method returns the object that was passed to the function.

Browser Support:

ChromeYes
EdgeYes
Firefox1.5
OperaYes

Example 1

Output:

22

Example 2

Output:

542

Example 3

Output:

17





Latest Courses