VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-object-defineproperty-method/

⇱ JavaScript Object defineProperty() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Object defineProperty() Method

Last Updated : 12 Jul, 2025

The Object.defineProperty() method in JavaScript is a Standard built-in object which defines a new property directly on an object or it can also modify the existing property of an object and return the object. 

Syntax:

Object.defineProperty(obj, prop, descriptor)

Parameters:

This method accepts three parameters as mentioned above and described below:

  • Obj: This parameter holds the Object on which the user is going to define the property.
  • Prop: This parameter holds the name of a property that is going to be defined or modified.
  • Descriptor: This parameter holds the descriptor for the property being defined or modified.

Return Value:

  • This method returns the object which is passed as the argument to the function. 

Example 1: In this example, we will add new properties to an object and print it in the console using the Object.defineProperty() method in JavaScript.

Output:

65
108

Example 2: In this example, we will add new properties to an object and print it in the console using the Object.defineProperty() method in JavaScript.

Output:

6
4
4
8
8

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers:

The browsers supported by Object.defineProperty() method are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari
  • Edge
Comment