JavaScript Debugging: Chrome DevTools, Breakpoints & Console API Mastery

Debugging is the diagnostic discipline of identifying, isolating, and rectifying defects in computer software. Professional JavaScript engineers rely on browser Developer Tools rather than simple console.log() statements to analyze memory states and step through execution lines.

Beyond console.log: The Professional Console API

// 1. console.table() - Renders arrays/objects in beautiful readable tables
const students = [
    { id: 101, name: "Vikram", marks: 92 },
    { id: 102, name: "Pooja", marks: 88 },
    { id: 103, name: "Rahul", marks: 95 }
];
console.table(students);

// 2. console.time() and console.timeEnd() - Benchmarking performance
console.time("LoopPerformance");
let sum = 0;
for (let i = 0; i < 1000000; i++) sum += i;
console.timeEnd("LoopPerformance"); // Outputs: LoopPerformance: 2.14ms

// 3. console.trace() - Prints the complete Call Stack trace to this point
function deeplyNestedFunc() {
    console.trace("Where was I called from?");
}

Interactive Breakpoints & The debugger Statement

Inserting the debugger; statement freezes browser execution at that line, launching DevTools automatically:

function calculateTax(income) {
    debugger; // Browser pauses here if F12 DevTools is open!
    let rate = (income > 500000) ? 0.2 : 0.05;
    return income * rate;
}
calculateTax(750000);

University Lab & Viva Voce Corner

DevTools Stepping Controls:

  • Step Over (F10): Executes next line without entering inside function bodies.
  • Step Into (F11): Steps directly inside the invoked function body line-by-line.
  • Step Out (Shift + F11): Executes the remainder of current function and returns to caller.
  • Resume Script Execution (F8): Resumes normal execution until next breakpoint.

Next Step

Congratulations on completing Tier 2: Control Flow & Loops! Now let us explore collections and memory structures. Proceed to Tier 3: JavaScript Arrays & Index Traversal →

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!