JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionstooling
PrevNext

Learn the concept

Debugging with Chrome DevTools

tooling
mid
debugging

What debugging tools and techniques should you know?

debugging
devtools
console
breakpoints
Quick Answer

Use Chrome DevTools for debugging (Sources panel, breakpoints, watch expressions), console methods beyond log (table, trace, time), debugger statement, VS Code debugger with launch configs, and React/Vue DevTools for framework-specific debugging.

Detailed Explanation

Chrome DevTools:

  • Sources panel for breakpoints
  • Network panel for requests
  • Performance panel for profiling
  • Application panel for storage

Console Methods:

  • console.log, warn, error
  • console.table for arrays/objects
  • console.trace for stack traces
  • console.time/timeEnd for timing
  • console.group for grouping

Breakpoints:

  • Line breakpoints
  • Conditional breakpoints
  • DOM breakpoints
  • XHR breakpoints
  • debugger statement

Code Examples

Console debugging techniquesJavaScript
// Basic logging with formatting
console.log('Value:', value);
console.log('%c Styled', 'color: blue; font-size: 20px');

// Table for arrays/objects
const users = [{name: 'Alice', age: 25}, {name: 'Bob', age: 30}];
console.table(users);
console.table(users, ['name']); // Only show name column

// Stack trace
function foo() {
  function bar() {
    console.trace('Trace from bar');
  }
  bar();
}
foo();

// Timing
console.time('fetch');
await fetch('/api/data');
console.timeEnd('fetch'); // fetch: 123.456ms

// Grouping
console.group('User Details');
console.log('Name:', user.name);
console.log('Email:', user.email);
console.groupEnd();

// Conditional logging
console.assert(value > 0, 'Value should be positive');

// Count calls
function processItem() {
  console.count('processItem called');
}

Real-World Applications

Use Cases

Troubleshooting unexpected behavior in a React component's lifecycle or state updates

Using React DevTools to inspect component hierarchies, props, state, and hooks in real-time. Setting breakpoints in Chrome DevTools to step through component rendering logic and identify the exact line of code causing the issue.

Identifying the root cause of an error in a Node.js backend API that only occurs in a specific request scenario

Attaching the VS Code debugger to the Node.js process using a `launch.json` configuration, setting conditional breakpoints, and inspecting variables in the call stack to trace the execution flow and pinpoint the bug.

Optimizing a complex algorithm or data processing function that is causing performance bottlenecks in a web application

Using `console.time()` and `console.timeEnd()` to measure execution durations, and the Chrome DevTools Performance tab to record a profile, analyze flame charts, and identify long-running tasks or excessive re-renders.

Mini Projects

Chrome DevTools Debugging Challenge

beginner

Take a small web application with a known bug (e.g., incorrect calculation, UI not updating). Use only Chrome DevTools (breakpoints, watch expressions, console) to identify and fix the bug.

Node.js Debugger Setup

intermediate

Create a simple Node.js script with a logical error. Configure `launch.json` in VS Code to debug the script, practice stepping through code, and inspect variables to find the bug.

Industry Examples

Google (Chrome DevTools)

Google's own developers rely heavily on Chrome DevTools for debugging their web applications, from search to Gmail. The tool suite is continuously improved based on internal needs for diagnosing complex performance and functional issues.

Microsoft (VS Code Debugger)

Microsoft's VS Code provides a powerful integrated debugger that is widely used by developers working on Node.js applications, TypeScript projects, and frontend frameworks. Its rich feature set for breakpoints, variable inspection, and call stack analysis is essential for debugging large-scale applications.

Resources

Chrome DevTools

docs
Previous
How do you set up CI/CD for a JavaScript project?
Next
How do you set up a testing environment with Jest?
PrevNext