JavaScript Proxy handler.get() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Proxy trap

Definition

handler.get(target, property, receiver) is a trap that runs when you read a property of a Proxy, for example proxy.name or proxy["name"]. It is the most used trap, and a good one to learn first.

Inside the trap you decide what value the reader gets. You can return the real value, a default value, a calculated value or even throw an error. To read the real value in the normal way, use Reflect.get(target, property, receiver).

Remember
const handler = {
  get(target, property, receiver) { ... }
};

target    → the original object
property  → the name (a string or a symbol)
receiver  → the proxy (or an object that inherits from it)

return value → the value the reader gets

Syntax

Add a get trap to the handler of a Proxy.

JavaScript
const user = new Proxy({ name: "Ann" }, {
  get(target, key, receiver) {
    if (key in target) {
      return Reflect.get(target, key, receiver);
    }
    return "unknown";
  }
});

console.log(user.name);   // Ann
console.log(user.age);    // unknown
CallWhat it does
proxy.nameReading with a dot runs the trap.
proxy["name"], proxy[0]Reading with square brackets runs it too. Numbers arrive as strings.
Reflect.get(proxy, "name")The function-style version.
Object.create(proxy).nameAn object that inherits from the Proxy also runs the trap when the property is not found on it.

A standard JavaScript Proxy trap (ES2015). You write it inside the handler object that you pass to new Proxy(). JavaScript calls it for you. No import required. Siblings: Proxy.revocable(), handler.apply(), handler.construct(), handler.defineProperty(), handler.deleteProperty(), handler.getOwnPropertyDescriptor(), handler.getPrototypeOf(), handler.has(), handler.isExtensible(), handler.ownKeys(), handler.preventExtensions(), handler.set(), handler.setPrototypeOf().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
handler.get(target, property, receiver)

// target   : the original object
// property : a string or a symbol
// receiver : the proxy, or an object that inherits from it
// returns  : any value

Parameters

ParameterDescription
targetThe original object that the Proxy wraps.
propertyThe name of the property that is being read: a string or a symbol. A number such as list[0] arrives as the string "0".
receiverThe object that was used for the read. It is normally the Proxy itself. Pass it on to Reflect.get() so that getters use the right this.

Return Value

Return ValueDescription
Any valueWhatever the trap returns is what the reader gets.
TypeError (thrown)The trap broke a rule, for example by returning a different value for a read-only, non-configurable property of the target.

JavaScript Examples

Example 1 — Give a Default Value for Missing Properties

Normally a missing property gives undefined. With a get trap, you can return something more helpful.

JavaScript
const settings = new Proxy({ theme: "dark" }, {
  get(target, key, receiver) {
    if (key in target) {
      return Reflect.get(target, key, receiver);
    }
    return "n/a";
  }
});

console.log(settings.theme);
console.log(settings.language);
console.log("Has language: " + ("language" in settings));
Try It Yourself

How It Works

  1. Check the target. key in target asks whether the property really exists. If it does, Reflect.get() returns the real value.
  2. Fallback. For language, which does not exist, the trap returns "n/a" instead of undefined.
  3. Nothing was added. The default is only returned. The in check shows that language was not created on the object.

Example 2 — Read an Array from the End

A trap can make up new behaviour. This Proxy lets you write list[-1] to get the last item, like in some other languages.

JavaScript
const list = new Proxy(["a", "b", "c"], {
  get(target, key, receiver) {
    if (typeof key === "string") {
      const index = Number(key);
      if (Number.isInteger(index) && index < 0) {
        return target[target.length + index];
      }
    }
    return Reflect.get(target, key, receiver);
  }
});

console.log("Last: " + list[-1]);
console.log("Second last: " + list[-2]);
console.log("First: " + list[0]);
console.log("Length: " + list.length);
console.log("Joined: " + list.join(""));
Try It Yourself

How It Works

  1. Keys are strings. The number -1 arrives as the string "-1". Number(key) turns it back, and typeof key === "string" keeps symbols away from Number().
  2. Count from the end. For a negative whole number, the trap returns target[target.length + index], so -1 means the last item.
  3. Everything else is normal. list[0], length and join() go through Reflect.get() and work as before.

Example 3 — Count Reads and Follow the Rules

Count how often each property is read. Then see that a trap cannot return a wrong value for a frozen property. The catch block prints the error type only.

JavaScript
const counts = {};
const counted = new Proxy({ a: 1, b: 2 }, {
  get(target, key, receiver) {
    counts[key] = (counts[key] || 0) + 1;
    return Reflect.get(target, key, receiver);
  }
});

counted.a;
counted.a;
counted.b;
console.log("Reads: " + JSON.stringify(counts));

const frozen = Object.freeze({ pi: 3.14 });
const liar = new Proxy(frozen, {
  get() {
    return 3;
  }
});

try {
  liar.pi;
} catch (err) {
  console.log("Wrong value for frozen property: " + err.name);
}
Try It Yourself

How It Works

  1. Count by name. Each read adds one to counts[key]. The trap then forwards the read, so the Proxy still works as normal.
  2. Two reads of a. a was read twice and b once, which the JSON text shows.
  3. A frozen value cannot change. pi is read-only and non-configurable. A trap that returns 3 instead of 3.14 is caught by JavaScript and throws a TypeError.

Browser & Runtime Support

handler.get() is part of ES2015 (ES6), together with the Proxy object and the Reflect object. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

handler.get()

Supported in Chrome 49+, Edge 12+, Firefox 49+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 49+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 49+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 36+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 49+ · Chromium based
Supported
Node.js 6+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
handler.get() Excellent

Bottom line: Safe to use in every current browser and in Node.js. A Proxy cannot be faked in old browsers, so do not use it where Internet Explorer must work.

Frequently Asked Questions

It is a method of the handler object that runs when a property of a Proxy is read. It receives the target, the property name and the receiver, and whatever it returns is the value that the reader gets.
Use Reflect.get(target, property, receiver). It reads the property from the target in the normal way, including getters and inherited properties, and you can return the result.
JavaScript itself reads properties such as length, then, toString and Symbol.iterator, for example when you log an object, use await, or loop over it. Always forward names you do not handle with Reflect.get().
It is the object that the property was read from. Normally it is the Proxy. If an object inherits from the Proxy, it is that object. Pass it to Reflect.get() so that getters get the right this value.
Almost anything. The only limit is that for a read-only, non-configurable data property of the target, the trap must return the real value. Otherwise JavaScript throws a TypeError.

Next: handler.getOwnPropertyDescriptor()

Learn how a Proxy can watch and change property descriptors with the getOwnPropertyDescriptor trap.

handler.getOwnPropertyDescriptor() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful