JavaScript Proxy — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Proxy lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Intercept a read
easy10 minCreate a Proxy that passes reads straight through.
- 2
Log every read
easy10 minRecord which keys were read through the proxy.
- 3
Validate a write
easy10 minReject a negative age through a set trap.
- 4
Supply a default for a missing key
easy10 minReturn a fallback string for any property not on the object.
- 5
Use the has trap
medium10 minMake one extra key always report as present.
Find the bug(5)
- 1
Fix the set trap that forgets to store the value
easy8 minThe trap must actually assign the value on the target.
- 2
Fix the set trap missing its return value
easy8 minA set trap must return true, or the assignment is reported as failed even though the value was stored.
- 3
Fix the validation checking the wrong key
easy8 minThe validation compares against the wrong property name.
- 4
Fix the direct target read counted as a proxy read
easy8 minReading the original target bypasses the trap entirely, so nothing is counted.
- 5
Fix the has trap that ignores the real object
easy8 minAny key not specially handled should fall back to checking the object.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace