> 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="https://1584857390-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvoqcCoqFcnxmEmzndTAj%2Fuploads%2F3x6W1bzpVgvlYuWWlQDB%2F240528-1.png?alt=media&amp;token=3192e7ac-2386-4e96-935c-990e146ccc61" alt=""><figcaption></figcaption></figure>
