Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Create a factory function that returns an object with increment, decrement, and getValue methods. Each returned method closes over a shared count variable, demonstrating how closures preserve access to their enclosing scope even after the outer function returns.
Inner functions retain a reference to outer variables even after the outer function returns. Each call to createCounter creates a new scope with its own independent count variable.
Updated Feb 2026