Watching Object Properties and Nested Values
You'll learn how to monitor complex objects with nested structures in the debugger to track exactly how state changes deep within your data.
The Challenge of Deep Objects
When debugging applications with complex state—think user profiles with addresses, settings, and preferences nested several levels deep—it's not enough to watch just the parent object. You need visibility into specific nested properties that might be changing without obvious surface-level indicators.
How Watch Expressions Handle Nesting
In the debugger's Watch panel, you can add expressions that drill down into nested structures using dot notation or bracket notation:
user.profile.settings.theme
cart.items[0].price
state.ui.modals['confirmDialog'].visible
Each watch expression evaluates continuously as you step through code, showing you the exact moment a nested value changes—even if the parent object reference stays the same.
Property Path Strategies
Dot notation works for simple, known property names. Bracket notation lets you watch dynamic keys or array indices. You can even watch computed expressions:
users.filter(u => u.active).length
config.features?.darkMode ?? 'default'
The debugger re-evaluates these each step, making it easy to spot when a deeply nested flag flips or an array element updates.
When to Use This Technique
This approach shines when:
- State mutations happen deep in nested objects
- You suspect a specific property is changing unexpectedly
- Parent object logging is too noisy or vague
- You need to track changes across multiple function calls
Key Takeaway: Watch expressions with property paths let you monitor specific nested values in complex objects, revealing state changes that would otherwise be invisible in parent-level inspection.