The JavaScript Event Loop Visualizer has been transformed from using hard-coded steps to dynamically analyzing user-provided code.
-
Monaco Code Editor Integration
- Full-featured code editor powered by Monaco (VS Code's editor)
- Syntax highlighting for JavaScript
- Light/dark theme support
- 400px height with line numbers
-
Dynamic Code Analysis
- Real-time parsing of JavaScript code
- Automatic detection of:
console.log()statementssetTimeout()callsasync/awaitpatterns- Promise creation and
.then()chains
- Smart event loop step generation
-
Interactive Workflow
- Write or edit JavaScript code in the editor
- Click "Visualize" to analyze and generate steps
- Use playback controls to step through execution
- Watch queues and call stack update in real-time
- CodeEditor.tsx - Monaco editor wrapper with "Visualize" button
- code-analyzer.ts - Analyzes JavaScript and generates event loop steps
- VisualizerExperience.tsx - Now includes code editor and manages visualization state
- use-event-loop-visualizer.ts - Accepts dynamic steps instead of hard-coded ones
The editor comes pre-loaded with a comprehensive example showing:
- Synchronous code execution
- setTimeout (macrotasks)
- async/await (microtasks)
- Promises and .then() chains
- User writes JavaScript code in the Monaco editor
- Clicks "Visualize" button
- Code analyzer parses the code line-by-line
- Detects async patterns (setTimeout, promises, async/await)
- Generates step-by-step execution sequence
- Visualizer displays queues, call stack, and console output
- User can play/pause/step through execution
- No AST parsing - Uses simple line-by-line analysis for reliability
- Pattern matching - Detects common async patterns via regex
- State tracking - Maintains call stack, microtask queue, and callback queue
- Event loop simulation - Follows correct microtask → macrotask order
Visit http://localhost:3000 and try:
- Modifying the default code
- Adding more
setTimeoutcalls - Creating promise chains
- Using async/await patterns
- Seeing how microtasks execute before macrotasks
The visualizer will automatically adapt to your code!