Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Reflect — explicit object operations

Reflect provides static methods for reading, writing, and inspecting objects. A Boolean write result lets you check whether an operation succeeded, but does not mean the method can never throw.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Reflect.get(target, key[, receiver])
Reflect.set(target, key, value[, receiver])
Reflect.defineProperty(target, key, descriptor)
Reflect.ownKeys(target)

Reflect is a built-in ECMAScript object, not a function or constructor: Reflect() and new Reflect() throw TypeError. Its methods expose operations corresponding to objects' internal mechanisms.

Reflect.get reads a property, while Reflect.set attempts to write it and returns a Boolean, not the assigned value. The optional receiver in both methods defaults to target and determines this when invoking getters or setters. Reflect.ownKeys returns all own string and symbol keys, including non-enumerable ones; it excludes inherited keys.

Reflect.defineProperty returns false when an object rejects a valid descriptor, whereas Object.defineProperty throws in that situation. A Boolean result does not guarantee freedom from exceptions: invalid arguments and code in getters, setters, or Proxy traps can cause them. Property operations require an object as target.

In the example, the property is non-enumerable and non-writable. Reflect.set returns false even in strict mode, the value remains 10, and Reflect.ownKeys still finds the key.

Examples

"use strict";
const target = {};
Reflect.defineProperty(target, "score", {
  value: 10,
  writable: false,
  enumerable: false,
  configurable: false
});
console.log(Reflect.get(target, "score"));
console.log(Reflect.set(target, "score", 20));
console.log(Reflect.ownKeys(target).join(","));
console.log(Reflect.get(target, "score"));

Result

10
false
score
10

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources