The JavaScript Reflect API: Reflect.get, set, has, ownKeys, apply and construct
Learn the Reflect API: thirteen functions that perform JavaScript's internal object operations directly, how they differ from Object methods (booleans instead of exceptions), the receiver argument for getters and setters, Reflect.apply and Reflect.construct with new.target, and its role in Proxy.
kvi5hnuCode Sprout team member5 min readOn this page
Every JavaScript object supports the same small set of internal operations: get a property, set one, check one exists, delete one, list keys, read the prototype, and so on. Syntax and Object methods trigger them indirectly (obj.x, key in obj, delete obj.x, Object.keys). Reflect (ES2015) exposes each of these operations as a plain function. That gives you three things:
- a function form for operators (
Reflect.has(obj, key)instead ofkey in obj), handy for passing operations around; - cleaner results than some older
Objectmethods (booleans instead of exceptions); - the exact building blocks that Proxy handlers (articles 105 and 106) need to forward operations.
(Template literal tags, another metaprogramming feature, are covered in article 16.)
The 13 operations
Reflect is a plain object (like Math, not a constructor) with 13 methods, one per internal operation. Each has a Proxy trap with the same name and the same parameters:

const settings = { theme: "dark", [Symbol("id")]: 7 };
Object.defineProperty(settings, "hidden", { value: true });
console.log(Reflect.get(settings, "theme")); // settings.theme
console.log(Reflect.set(settings, "theme", "light")); // settings.theme = "light"
console.log(Reflect.has(settings, "toString")); // "toString" in settings
console.log(Reflect.ownKeys(settings)); // every own key
console.log(Reflect.deleteProperty(settings, "theme"), settings);
dark
true
true
[ 'theme', 'hidden', Symbol(id) ]
true { Symbol(id): 7 }
Reflect.ownKeys is the most complete key listing in the language: own string and symbol keys, enumerable or not, in property order. It's equivalent to Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj)).
Booleans instead of exceptions
Several Object methods throw on failure, and plain assignment fails silently in sloppy mode. The Reflect versions return true or false instead, so you can branch on the result:
const locked = Object.freeze({ x: 1 });
console.log(Reflect.set(locked, "x", 2)); // assignment would be ignored or throw
console.log(Reflect.defineProperty(locked, "y", { value: 1 }));
console.log(Reflect.deleteProperty(locked, "x"));
console.log(Reflect.setPrototypeOf(locked, {}));
try {
Object.defineProperty(locked, "y", { value: 1 });
} catch (err) {
console.log("Object.defineProperty threw", err.name);
}
false
false
false
false
Object.defineProperty threw TypeError
That makes them convenient in code that should handle failure without try...catch:
if (!Reflect.defineProperty(target, key, descriptor)) {
console.warn(`Could not define ${String(key)}`);
}
Another difference: Reflect methods are strict about their target. They throw a TypeError if it isn't an object, where Object.getPrototypeOf(1) quietly converts the primitive (returning Number.prototype).
The receiver argument
Reflect.get(target, key, receiver) and Reflect.set(target, key, value, receiver) take an optional receiver: the value used as this if the property turns out to be a getter or setter. Normally it's the object itself, but it can be any object:
const account = {
balance: 100,
get summary() {
return `balance: ${this.balance}`;
},
};
console.log(Reflect.get(account, "summary"));
console.log(Reflect.get(account, "summary", { balance: 5 }));
balance: 100
balance: 5
This seems obscure, but it's exactly what inheritance needs: when you read an inherited getter through child.prop, the getter is found on the prototype yet must run with this === child. When a Proxy sits in the prototype chain or wraps an object with getters, forwarding the receiver keeps this correct (article 106 shows the bug that happens otherwise).
Reflect.apply
Reflect.apply(fn, thisArg, args) calls a function with a given this and an array of arguments. It's the same as fn.apply(thisArg, args) from article 68, but it can't be broken by a function that has its own apply property, and it reads more clearly:
function total(...amounts) {
return amounts.reduce((sum, n) => sum + n, this.base);
}
console.log(Reflect.apply(total, { base: 100 }, [1, 2, 3]));
console.log(Reflect.apply(Math.max, undefined, [3, 9, 4]));
106
9
Today the spread syntax (fn.call(thisArg, ...args)) covers most everyday uses. Reflect.apply shines in Proxy apply traps, where you receive exactly (target, thisArg, args).
Reflect.construct
Reflect.construct(Class, args, newTarget?) is a function form of new Class(...args). The optional third argument sets new.target, the constructor that new was "really" called on. It decides the prototype of the created object:
class Shape {
constructor(name) {
this.name = name;
this.createdAs = new.target.name;
}
}
class Circle extends Shape {}
const s = Reflect.construct(Shape, ["plain"]);
const c = Reflect.construct(Shape, ["round"], Circle); // run Shape's constructor, but as a Circle
console.log(s, c.createdAs, c instanceof Circle);
Shape { name: 'plain', createdAs: 'Shape' } Circle true
Like new, it throws a TypeError if the target isn't a constructor (arrow functions and methods aren't).
The other methods
The remaining methods mirror Object functions, with the boolean-result and strict-target differences described above:
| Reflect | Equivalent | Difference |
|---|---|---|
getOwnPropertyDescriptor(o, k) | Object.getOwnPropertyDescriptor | throws if o isn't an object |
getPrototypeOf(o) | Object.getPrototypeOf | throws if o isn't an object |
setPrototypeOf(o, p) | Object.setPrototypeOf | returns false instead of throwing |
isExtensible(o) | Object.isExtensible | throws for primitives (Object returns false) |
preventExtensions(o) | Object.preventExtensions | returns a boolean instead of the object |
defineProperty(o, k, d) | Object.defineProperty | returns a boolean instead of throwing |
When to use Reflect
- Inside Proxy handlers, always: forward the default behavior with
Reflect.<trap>(...arguments). - When you need an operator as a function:
keys.filter((k) => Reflect.has(obj, k)). - When a success flag is more convenient than an exception.
Reflect.ownKeysfor "really all keys" (deep clone and serialization utilities).
For ordinary property access, keep using normal syntax: obj.x is clearer than Reflect.get(obj, "x").
Common questions
Why does Reflect exist if Object already has most of these methods?
To give every internal operation a consistent function form, with a uniform signature that matches the Proxy traps, boolean results, and no implicit conversion of the target. New reflection methods are added to Reflect rather than Object.
Is Reflect a constructor?
No. Like Math and JSON, it's an ordinary object holding functions. new Reflect() throws a TypeError.
What's the difference between Reflect.ownKeys and Object.keys?
Object.keys returns only own enumerable string keys. Reflect.ownKeys returns all own keys: strings and symbols, enumerable or not.
When do I need the receiver argument?
When forwarding a property access from a Proxy trap or a wrapper, so that getters and setters run with the correct this. In normal code you can omit it.
Summary
Reflecthas 13 functions, one for each internal object operation, each matching a Proxy trap by name and signature.Reflect.set,defineProperty,deleteProperty,setPrototypeOfandpreventExtensionsreport success as booleans instead of throwing.Reflectmethods throw on non-object targets instead of converting primitives.Reflect.get/settake a receiver that becomesthisfor getters and setters.Reflect.applycalls functions safely;Reflect.constructcreates objects, optionally with a differentnew.target.Reflect.ownKeyslists every own key, including symbols and non-enumerables.
Practice Questions
What does this print?
const o = Object.defineProperty({}, "id", { value: 1 });
console.log(Reflect.set(o, "id", 2), o.id, Reflect.ownKeys(o));
Answer
false 1 [ 'id' ]. The property is non-writable, so Reflect.set returns false and the value stays 1. ownKeys includes it even though it's non-enumerable.
Rewrite this try...catch using Reflect.
try {
Object.defineProperty(obj, "x", desc);
ok();
} catch {
fail();
}
Answer
if (Reflect.defineProperty(obj, "x", desc)) ok();
else fail();
What does this print?
const parent = { name: "parent", get who() { return this.name; } };
console.log(Reflect.get(parent, "who", { name: "child" }));
Answer
child. The third argument is the receiver, used as this when the getter runs.
Which call throws, and which returns a value?
Object.getPrototypeOf("text");
Reflect.getPrototypeOf("text");
Answer
Object.getPrototypeOf("text") converts the string to an object and returns String.prototype. Reflect.getPrototypeOf("text") throws a TypeError, because Reflect methods require an object target.
Previous: Well-Known Symbols in JavaScript: Symbol.toPrimitive, toStringTag, hasInstance, species and More
Next: JavaScript Proxy Explained: Handlers, Traps and Intercepting Object Operations

More in JavaScript Course
Quiz: Modern JavaScript, ES2022 to ES2027 Features
Twenty-four questions on what's new in JavaScript: change-array-by-copy methods, groupBy, Set methods, iterator helpers, Promise.withResolvers and Promise.try, RegExp.escape and the v flag, using declarations, Error.isError, Base64 typed arrays, Temporal, getOrInsert and Iterator.zip.
Quiz: JavaScript's Delicate Details (Spec-Level Edge Cases)
Twenty-eight questions on the fine print of JavaScript, drawn from the ECMAScript specification and MDN: sparse arrays, -0, number limits, JSON edge cases, Date overflow, UTF-16, property attributes, inherited accessors, comparison quirks, labels, regex state and Symbol.toPrimitive.
Quiz: JavaScript Interview Questions (Output Prediction and Core Concepts)
Thirty classic JavaScript interview questions: closures in loops, hoisting and the TDZ, this, the event loop and microtasks, async/await, coercion, sorting and parseInt traps, prototypes, copying, finally, generators and bind. Every answer was verified by running it.
Quiz: JavaScript Course Final Exam (All 17 Parts)
The final exam for the JavaScript course: thirty questions spanning all seventeen parts, from syntax, types and operators through objects, arrays, functions, classes, modules, the standard library, iterators, async code, metaprogramming, browsers, Node.js and tooling.
Discussion
Sign in to ask a question or share what you learned.