debuggerDebugging is the process of identifying, diagnosing, and fixing code errors. JavaScript provides rich console logging APIs, devtool breakpoints, and the inline debugger statement.
flowchart TD
DebugProcess["Debugging Strategy"] --> ConsoleLogs["Console Logging: console.log(), console.table(), console.group()"]
DebugProcess --> Breakpoints["Browser DevTools Breakpoints (Sources Tab)"]
DebugProcess --> DebuggerStmt["Inline 'debugger;' Statement (Pauses execution thread)"]
| Method | Signature | Description |
|---|---|---|
console.log() |
console.log(val) |
Standard information logging. |
console.error() |
console.error(msg) |
Red error formatting with stack trace. |
console.warn() |
console.warn(msg) |
Yellow warning log. |
console.table() |
console.table(arr) |
Displays tabular data cleanly in devtools. |
console.time() / timeEnd() |
console.time("id") |
Measures execution duration in milliseconds. |
// Demonstrating Console API features and performance timing
// 1. Formatted Tabular Output
const developers = [
{ id: 1, name: "Maksudur", role: "Architect" },
{ id: 2, name: "Sarah", role: "Frontend Developer" }
];
console.log("--- Console Table Output ---");
console.table(developers);
// 2. Grouped Console Logs
console.group("User Auth Pipeline");
console.log("Step 1: Validating credentials...");
console.log("Step 2: Generating JWT Token...");
console.groupEnd();
// 3. Execution Time Benchmarking
console.time("Array Transformation");
const largeList = Array.from({ length: 100000 }, (_, i) => i);
const doubledList = largeList.map(n => n * 2);
console.timeEnd("Array Transformation");
// 4. Conditional Assertions
console.assert(developers.length > 5, "Developer team count is less than 5!");
// 5. Inline Breakpoint Trigger (Un-comment to trigger DevTools breakpoint)
function debugMe() {
const x = 10;
// debugger; // Execution thread pauses here if DevTools is open!
return x * 2;
}
debugMe();
console.table() for Arrays of Objects: console.table() presents complex arrays in filterable tables, making payload inspection fast.console.log() and debugger statements from production bundles using build tools like Terser or Vite plugins.true.What does console.assert(1 === 2, "Validation Failed"); output in the developer console?
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.