CKTIS / JavaScript
Reflect.getPrototypeOf — reading an object's prototype
Reflect.getPrototypeOf(target) returns an object's immediate prototype or null. It requires an object: primitive values cause a TypeError rather than the wrapper conversion performed by Object.getPrototypeOf.
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.getPrototypeOf(target)Reflect.getPrototypeOf(target) calls the argument's internal [[GetPrototypeOf]] method. For an ordinary object, it reads the immediate prototype without searching the entire chain. The result is an object or null, meaning there is no prototype. This is not a read of the .prototype property that functions may have.
The target argument must be an object; functions are objects too. Every primitive value, including null and undefined, causes a TypeError. Omitting the argument also causes a TypeError, because its value is then undefined.
For objects, Object.getPrototypeOf(target) uses the same internal operation. The difference concerns primitives: Object.getPrototypeOf wraps them in objects, except for null and undefined, which it rejects. Thus, Object.getPrototypeOf("abc") returns String.prototype, whereas Reflect.getPrototypeOf("abc") throws.
For a Proxy, the read can invoke the getPrototypeOf trap, so it is not necessarily free of side effects. The trap must return an object or null; for a non-extensible target object, the result must match its actual prototype. Violating these rules or using a revoked proxy causes a TypeError; exceptions from the trap propagate.
Examples
const proto = { role: "base" };
const item = Object.create(proto);
console.log(Reflect.getPrototypeOf(item) === proto);
console.log(Reflect.getPrototypeOf(Object.create(null)) === null);
console.log(Object.getPrototypeOf("abc") === String.prototype);
try {
Reflect.getPrototypeOf("abc");
} catch (error) {
console.log(error instanceof TypeError);
}Result
true true true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.