JavaScript debugging is the systematic process of inspecting runtime values, tracing execution paths, and isolating why code produces unexpected results. Moving beyond basic console.log() to DevTools breakpoints and console.table() cuts troubleshooting time dramatically.
console Methods Beyond console.log()The Console API offers specialized formatters that make noisy state much easier to scan:
console.log({ user, total }): Wrapping variables in {} prints labeled key-value pairs so you never lose track of which number belongs to which variable.console.table(arrayOfObjects): Renders arrays of objects as a clean sortable table in browser DevTools and Node.js.console.warn() / console.error(): Highlights issues in yellow or red along with a collapsible stack trace.console.time("label") / console.timeEnd("label"): Measures exact elapsed milliseconds between two lines.debugger KeywordInserting debugger; in code (or clicking a line number in DevTools Sources) pauses execution right at that line while DevTools is open. While paused, you can hover over variables, inspect the Call Stack, and step line by line.
function computeCartTotal(items) {
console.time("cartCalc");
let subtotal = 0;
for (const item of items) {
if (typeof item.price !== "number" || item.price < 0) {
console.warn("Skipping invalid price item:", item);
continue;
}
subtotal += item.price * item.qty;
}
console.timeEnd("cartCalc");
return Number(subtotal.toFixed(2));
}
const sample = [
{ name: "Notebook", price: 8.5, qty: 2 },
{ name: "Broken Item", price: -5, qty: 1 },
];
console.table(sample);
console.log("Final subtotal:", computeCartTotal(sample));
debugger; statements to production: Leaving debugger; in shipped files pauses execution for users who open DevTools. Configure ESLint no-debugger to block it.structuredClone(obj) or JSON.stringify(obj) to snapshot exact state at that moment.Right-click a line number in the Sources panel and enter a condition like user.id === 42. Execution pauses only on the iteration where that expression is truthy.
Enable "Pause on caught/uncaught exceptions" in the DevTools Sources panel to freeze execution at the exact line an error is thrown.
Source maps (.map files) link minified production bundles back to your original readable ES6 or TypeScript lines inside DevTools.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.