JavaScript Module Patterns — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Module Patterns 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
Build a counter module
easy10 minKeep a count private and expose an increment method.
- 2
Hide private state
easy10 minShow that the private count cannot be read directly.
- 3
Use the revealing pattern
easy10 minDeclare two helpers privately and reveal only one.
- 4
Namespace under one global
easy10 minAttach a module to a single namespace object.
- 5
Compare the pattern with a plain object
medium10 minShow both approaches give the same result.
Find the bug(5)
- 1
Fix the private value exposed
easy8 mincount should not appear on the returned object.
- 2
Fix the IIFE never called
easy8 minWithout the trailing brackets, the function is never invoked.
- 3
Fix the helper revealed by mistake
easy8 minOnly double was meant to be exposed.
- 4
Fix the namespace overwritten
easy8 minReassigning MyApp loses whatever was already attached to it.
- 5
Fix the two separately built objects
easy8 minTwo separate object literals are never equal, even with identical contents.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace