<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx" -->

---
title: Proxy and Reflect | daily.dev
description: A deep-dive into JavaScript&#x27;s Proxy and Reflect objects. Covers how Proxy lets you intercept and redefine internal object operations (like [[Get]], [[Set]],...
canonical: https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Proxy and Reflect | daily.dev
og:description: A deep-dive into JavaScript&#x27;s Proxy and Reflect objects. Covers how Proxy lets you intercept and redefine internal object operations (like [[Get]], [[Set]],...
og:url: https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx
og:image: https://api.daily.dev/og/posts/i2kxp0yXX.png
og:image:alt: Proxy and Reflect
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Proxy and Reflect

**[Piccalilli](https://daily.dev/sources/piccalilli)** · 16 min read · 1 upvotes · 0 comments

## Summary

A deep-dive into JavaScript's Proxy and Reflect objects. Covers how Proxy lets you intercept and redefine internal object operations (like [[Get]], [[Set]], [[Delete]]) using handler traps, and how Reflect provides matching static methods that ensure your custom handlers still conform to the language specification's invariants. Practical examples progress from basic property interception to data validation, access counting, and building a lightweight reactive state system with subscriptions — all without third-party frameworks.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://piccalil.li/blog/proxy-and-reflect>

## Questions this post answers

### How do I use a JavaScript Proxy to validate property values before they're set on an object?

Define a set trap on the handler object passed to the Proxy constructor: check the incoming value's type, and if valid call Reflect.set(target, propertyKey, value) to complete the assignment; otherwise log an error and return false. Returning false signals to JavaScript that the [[Set]] operation failed, satisfying the ES-262 invariant that [[Set]] must return a boolean.

_For hands-on validation patterns like this, developers building resilient JS objects can find deep dives on daily.dev._

### Why should I use Reflect.set instead of directly assigning target[key] = value inside a Proxy set trap?

Reflect.set performs the [[Set]] operation and automatically returns the boolean value the specification requires, whereas a manual assignment like target[propertyKey] = value returns the assigned value itself, not a boolean. In strict mode, a proxy set trap that returns a falsy or non-boolean result throws a TypeError, so using Reflect.set avoids having to manually track and return the correct boolean per the ES-262 invariants for [[Set]].

_Anyone hardening proxy-based objects against spec violations can dig into these guardrails on daily.dev._

### How can I build a reactive state system in JavaScript without a framework using Proxy?

Wrap a target object in a Proxy whose set trap calls Reflect.set to update the value, then checks a Map of subscribed callbacks for that key and invokes each callback with the new value via callbackFunc.call(receiver, key). Consumers register interest with a subscribe method added to the proxied object, letting property changes trigger callbacks without any third-party state library.

_Developers weighing lightweight state solutions against reaching for a framework can explore this pattern on daily.dev._

## Similar posts on daily.dev

- [Vue Basics: Ultimate Guide to Vue 3 Reactivity](https://daily.dev/posts/vue-basics-ultimate-guide-to-vue-3-reactivity-l3lntlfjf) · Telerik · 52 upvotes · 1 comments
- [How \_\_proto\_\_, prototype, and Inheritance Actually Work in JavaScript](https://daily.dev/posts/how-proto-prototype-and-inheritance-actually-work-in-javascript-zlsteblbp) · freeCodeCamp · 4 upvotes · 0 comments
- [Simplifying JavaScript Prototypes in Constructor Invocation](https://daily.dev/posts/simplifying-javascript-prototypes-in-constructor-invocation-o5gw2maba) · Telerik · 0 upvotes · 0 comments
- [Recreating Stimulus: targets, actions and reactive values](https://daily.dev/posts/recreating-stimulus-targets-actions-and-reactive-values-sjsy5tcfk) · RUBYLAND · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Proxy and Reflect","url":"https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx"},"datePublished":"2026-07-09T12:11:25.790Z","dateModified":"2026-09-13T19:51:50.585Z","description":"A deep-dive into JavaScript's Proxy and Reflect objects. Covers how Proxy lets you intercept and redefine internal object operations (like [[Get]], [[Set]],...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bf64af7437b16a60bea6ff98c231c7ff?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bf64af7437b16a60bea6ff98c231c7ff?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Piccalilli","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Piccalilli","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/6864a3872e444ed8a46d4e28a71883e3","url":"https://daily.dev/sources/piccalilli"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript","timeRequired":"PT16M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Piccalilli","item":"https://daily.dev/sources/piccalilli"},{"@type":"ListItem","position":3,"name":"Proxy and Reflect"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/proxy-and-reflect-i2kxp0yxx#faq","mainEntity":[{"@type":"Question","name":"How do I use a JavaScript Proxy to validate property values before they're set on an object?","acceptedAnswer":{"@type":"Answer","text":"Define a set trap on the handler object passed to the Proxy constructor: check the incoming value's type, and if valid call Reflect.set(target, propertyKey, value) to complete the assignment; otherwise log an error and return false. Returning false signals to JavaScript that the [[Set]] operation failed, satisfying the ES-262 invariant that [[Set]] must return a boolean. For hands-on validation patterns like this, developers building resilient JS objects can find deep dives on daily.dev."}},{"@type":"Question","name":"Why should I use Reflect.set instead of directly assigning target[key] = value inside a Proxy set trap?","acceptedAnswer":{"@type":"Answer","text":"Reflect.set performs the [[Set]] operation and automatically returns the boolean value the specification requires, whereas a manual assignment like target[propertyKey] = value returns the assigned value itself, not a boolean. In strict mode, a proxy set trap that returns a falsy or non-boolean result throws a TypeError, so using Reflect.set avoids having to manually track and return the correct boolean per the ES-262 invariants for [[Set]]. Anyone hardening proxy-based objects against spec violations can dig into these guardrails on daily.dev."}},{"@type":"Question","name":"How can I build a reactive state system in JavaScript without a framework using Proxy?","acceptedAnswer":{"@type":"Answer","text":"Wrap a target object in a Proxy whose set trap calls Reflect.set to update the value, then checks a Map of subscribed callbacks for that key and invokes each callback with the new value via callbackFunc.call(receiver, key). Consumers register interest with a subscribe method added to the proxied object, letting property changes trigger callbacks without any third-party state library. Developers weighing lightweight state solutions against reaching for a framework can explore this pattern on daily.dev."}}]}
```

