Skip to main content

What does Reflect do?

What Reflect is

Reflect is a built-in object that contains a set of helper methods for working with objects: accessing properties, deleting them, creating them, calling functions, and so on.

In other words: Reflect is a set of "safe" counterparts to JS operators (in, delete, [], Object.defineProperty(), etc.), gathered in one place.


The main goals of Reflect:

  1. A single interface for low-level operations on objects → instead of different operators and functions (delete, in, Object.defineProperty, etc.)
  2. Working alongside Proxy → so you can delegate actions back to the original object.
  3. More predictable behavior → methods return true/false instead of throwing errors when an operation is impossible.

MethodWhat it doesCounterpart without Reflect
Reflect.get(obj, prop)Returns the value of a propertyobj[prop]
Reflect.set(obj, prop, value)Sets the value of a propertyobj[prop] = value
Reflect.has(obj, prop)Checks whether a property exists"prop" in obj
Reflect.deleteProperty(obj, prop)Deletes a propertydelete obj[prop]
Reflect.ownKeys(obj)Returns all keys (including Symbol)Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj))
Reflect.defineProperty(obj, prop, desc)Defines a propertyObject.defineProperty(obj, prop, desc)
Reflect.getOwnPropertyDescriptor(obj, prop)Gets a property descriptorObject.getOwnPropertyDescriptor(obj, prop)
Reflect.apply(fn, thisArg, argsArray)Calls a function with a context and argumentsfn.apply(thisArg, argsArray)
Reflect.construct(fn, argsArray)Creates an instance (like new fn(...))new fn(...argsArray)

A usage example

javascript
const user = { name: "Tim" }; console.log(Reflect.get(user, "name")); // "Tim" Reflect.set(user, "age", 25); console.log(user); // { name: "Tim", age: 25 } console.log(Reflect.has(user, "age")); // true Reflect.deleteProperty(user, "age"); console.log(Reflect.has(user, "age")); // false

Reflect and Proxy together

Reflect is often used inside Proxy traps, to "forward" the default behavior back to the target object (target).

Example:

javascript
const user = { name: "Tim" }; const proxy = new Proxy(user, { get(target, prop, receiver) { console.log(`Reading property: ${prop}`); // safer than target[prop]: return Reflect.get(target, prop, receiver); }, set(target, prop, value, receiver) { console.log(`Writing property: ${prop} = ${value}`); return Reflect.set(target, prop, value, receiver); } }); proxy.name; // Log: Reading property: name proxy.age = 30; // Log: Writing property: age = 30

Why do this? Because Reflect guarantees the correct forwarding of this and the internal context, unlike direct access via target[prop].


Summary

ItemDescription
Reflecta built-in object with methods for working with objects
Goalunify low-level operations (reading, writing, deleting, creating, etc.)
Featuresafe operator counterparts that return true/false instead of errors
Often usedinside Proxy traps

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.