How to Use the Console in Chrome DevTools
· Category: VS Code & Developer Tools
Short answer
The Console is a multipurpose tool for logging messages, running JavaScript, and viewing errors. It appears in its own tab or as a drawer in other panels.
Steps
- Open DevTools with
F12orCtrl+Shift+I, then click the Console tab. - View log messages from
console.log,warn, anderrorcalls. - Type JavaScript expressions at the bottom prompt and press Enter to execute.
- Use
$0to reference the currently selected DOM element. - Filter messages by level or text using the filter options.
Tips
- Use
console.table()to display arrays and objects in a readable table. - Interpolate values with
console.log("Value: %s", val). - Preserve logs across page reloads by enabling the setting in Console settings.
Common issues
- Cleared logs cannot be recovered; preserve them if needed.
- Some console errors originate from third-party scripts and are not actionable.