Interactive Demo: Break the Closure

Click the mysterious closure box to break it open and see what's inside. Watch the variables get captured in real-time.

?

🎉 A Closure is Just a Function + Its Environment!

That's it! A closure remembers variables from its outer scope even after the outer function has finished executing.

function createCounter() { let count = 0; // Captured variable return function() { count++; // Still accessible! return count; }; } const counter = createCounter(); console.log(counter()); // 1 console.log(counter()); // 2

The "mirage" shattered! Closures aren't complex - they're just functions with a backpack of variables they carry around.