An interactive explorer of John Resig's advanced JavaScript techniques. Write code, run it, see it visualized.
Start Exploring ↓A closure gives a function access to variables from its enclosing scope, even after that scope has finished executing. This is the foundation of private variables, callbacks, and most patterns in JavaScript.
Run the code below and watch the scope chain diagram update to show which variables each function can see.
Every JavaScript object has a hidden [[Prototype]] link. When you access a property, the engine walks up this chain until it finds it (or hits null). This is how inheritance works — no classes needed.
Run the code and see the prototype chain visualized as connected nodes.
thisThe value of this is determined by how a function is called, not where it's defined. This is one of the trickiest parts of JavaScript. There are four rules: default, implicit, explicit (call/apply/bind), and new.
Run the code to see which object this points to in each context.
this binding diagram — click Run to visualizeJavaScript is single-threaded. Timers don't execute at exact times — they queue a callback for "at least" that delay. Resig's key insight: setTimeout chains guarantee a gap between executions; setInterval fires regardless of whether the previous callback finished.
Resig calls regex one of the most underused features in JavaScript. Key techniques: pre-compilation for performance, exec() in a loop for global search with captures, and replace with a function for powerful transformations.
JavaScript can generate and execute code at runtime — via eval(), new Function(), and dynamic <script> tags. Resig shows this isn't just a footgun — it powers JSON parsing, templating engines, and even entire programming languages (Processing.js).
new Function() creates a function without closures — cleaner and safer than eval.
Resig's #1 rule: test the feature, not the browser. Use object detection and feature simulation instead of user-agent sniffing. Bugs get fixed — your workarounds should survive.
Try DOM manipulation with the live playground below. The preview updates in real time.
"There is nothing simple about creating effective, cross-browser, JavaScript code. But understanding how the very best libraries are constructed can provide great insight into how your own code can be constructed."
— John Resig
Every editor above is live. Modify the code, run it again, break things, fix them. That's how ninjas learn.