# Object.getOwnPropertyDescriptor() (ok)

Phương thức Object.getOwnPropertyDescriptor () trả về một đối tượng mô tả cấu hình của một thuộc tính cụ thể trên một đối tượng nhất định (nghĩa là một đối tượng hiện diện trực tiếp trên một đối tượng chứ không phải trong chuỗi nguyên mẫu của đối tượng). Đối tượng được trả về có thể thay đổi nhưng việc thay đổi nó không ảnh hưởng đến cấu hình của thuộc tính ban đầu.

```
const object1 = {
  property1: 42
};
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
console.log(descriptor1.configurable);
// expected output: true
console.log(descriptor1.value);
// expected output: 42
```

```
Object.getOwnPropertyDescriptor(obj, prop)
obj
The object in which to look for the property.
prop
The name or Symbol of the property whose description is to be retrieved.
```

### Description <a href="#description" id="description"></a>

This method permits examination of the precise description of a property. A property in JavaScript consists of either a string-valued name or a [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) and a property descriptor. Further information about property descriptor types and their attributes can be found in [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).

Phương pháp này cho phép kiểm tra mô tả chính xác của một tài sản. Thuộc tính trong JavaScript bao gồm tên có giá trị chuỗi hoặc Biểu tượng và bộ mô tả thuộc tính. Thông tin thêm về các loại bộ mô tả thuộc tính và các thuộc tính của chúng có thể được tìm thấy trong Object.defineProperty ().

A property descriptor is a record with some of the following attributes:

Bộ mô tả thuộc tính là một bản ghi có một số thuộc tính sau:

**value** The value associated with the property (data descriptors only).&#x20;

**writable** true if and only if the value associated with the property may be changed (data descriptors only). **get** A function which serves as a getter for the property, or undefined if there is no getter (accessor descriptors only).&#x20;

**set** A function which serves as a setter for the property, or undefined if there is no setter (accessor descriptors only).&#x20;

**configurable** true if and only if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.&#x20;

**enumerable** true if and only if this property shows up during enumeration of the properties on the corresponding object.

### Examples <a href="#examples" id="examples"></a>

#### Using Object.getOwnPropertyDescriptor <a href="#using_object.getownpropertydescriptor" id="using_object.getownpropertydescriptor"></a>

```
var o, d;
o = {
  get foo() {
    return 17;
  }
};
d = Object.getOwnPropertyDescriptor(o, 'foo');
// d is {
//   configurable: true,
//   enumerable: true,
//   get: /*the getter function*/,
//   set: undefined
// }
o = { bar: 42 };
d = Object.getOwnPropertyDescriptor(o, 'bar');
// d is {
//   configurable: true,
//   enumerable: true,
//   value: 42,
//   writable: true
// }
o = {
  [Symbol.for('baz')]: 73
}
d = Object.getOwnPropertyDescriptor(o, Symbol.for('baz'));
// d is {
//   configurable: true,
//   enumerable: true,
//   value: 73,
//   writable: true
// }
o = {};
Object.defineProperty(o, 'qux', {
  value: 8675309,
  writable: false,
  enumerable: false
});
d = Object.getOwnPropertyDescriptor(o, 'qux');
// d is {
//   value: 8675309,
//   writable: false,
//   enumerable: false,
//   configurable: false
// }
```

N**on-object coercion**

&#x20;In ES5, if the first argument to this method is not an object (a primitive), then it will cause a [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError). In ES2015, a non-object first argument will be coerced to an object at first.

Trong ES5, nếu đối số đầu tiên của phương thức này không phải là một đối tượng (nguyên thủy), thì nó sẽ gây ra Lỗi kiểu. Trong ES2015, đối số đầu tiên không phải đối tượng sẽ bị ép buộc vào một đối tượng lúc đầu.

```
Object.getOwnPropertyDescriptor('foo', 0);
// TypeError: "foo" is not an object  // ES5 code

Object.getOwnPropertyDescriptor('foo', 0);
// Object returned by ES2015 code: {
//   configurable: false,
//   enumerable: true,
//   value: "f",
//   writable: false
// }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascriptuse.gitbook.io/advanced/object.getownpropertydescriptor-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
