> For the complete documentation index, see [llms.txt](https://leejaelll.gitbook.io/dev_jaell/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leejaelll.gitbook.io/dev_jaell/javascript/proxy.md).

# Proxy 객체 활용하기

Proxy 객체 언제 사용하면 좋을까? 👉🏻 ***객체의 없는 속성들에 접근하면 undefined가 아닌 에러를 내보내고 싶을 때***

```javascript
const o = { foo: 'bar' };
const p = new Proxy(o, {
  get(target, prop) {
    if (prop in target) {
      return target[prop];
    }
    throw new Error(`${prop} 존재x`);
  },
});
```

<figure><img src="/files/jUGCn2pBXUk8nN5T8raP" alt=""><figcaption></figcaption></figure>
