Object

Object.defineProperties

Defines new or modifies existing properties directly on an object, returning the object

Syntax

JavaScript
Object.defineProperties(obj, props)

Parameters

ParameterTypeDescription
objobjectThe object on which to define or modify properties
propsPropertyDescriptorMapAn object whose keys represent property names and whose values are property descriptors

Return Value

The object that was passed to the function

Examples

Basic Usage
const obj: Record<string, unknown> = {};
Object.defineProperties(obj, {
  name: { value: 'Alice', enumerable: true },
  age: { value: 30, enumerable: true },
});
console.log(obj); // { name: 'Alice', age: 30 }
Practical Example
const point = {};
Object.defineProperties(point, {
  x: { value: 0, writable: true },
  y: { value: 0, writable: true },
});
Advanced Usage
const obj: Record<string, unknown> = {};
Object.defineProperties(obj, {
  id: { value: 1, writable: false, enumerable: true },
  type: { value: 'user', writable: false, enumerable: true },
});
console.log(Object.keys(obj)); // ['id', 'type']

Understanding Object.defineProperties

The Object.defineProperties method in JavaScript defines new or modifies existing properties directly on an object, returning the object. It belongs to the Object object and is one of the most widely used methods for working with object values in modern JavaScript and TypeScript applications.

The method signature is Object.defineProperties(obj, props). It accepts 2 parameters: obj, props. When called, it returns the object that was passed to the function. Understanding when and how to use defineProperties() helps you write more expressive, readable code.

Common use cases for Object.defineProperties include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like object-defineproperty, object-create, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Object.defineProperties is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Object Methods

Other methods in the Object object

Related Tools

More Object Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.