Object.defineProperty

Adds a property to an object, or modifies attributes of an existing property.

Syntax

defineProperty(object, propertyName, attributes)

Parameters

Return value

The object that was passed to the function.

Examples

let obj = {}
Object.defineProperty(obj, "speed", {
  value: 120,
  writable: true
});
obj.speed
120