Debugging Basics
๐ What is JavaScript Debugging? Debugging in JavaScript means finding and fixing errors in your code. Browser DevTools is your best friend: open with F12 (or right-click > Inspect), find the Console tab, and you see all console.log() output, error messages, and stack traces.

Appy Saysโฆ
Every developer spends as much time debugging as writing code. The devs who ship fast aren't the ones who write perfect code first time โ they're the ones who find and fix bugs fastest. The browser's DevTools is your X-ray machine.
What is JavaScript Debugging?
Debugging is finding and fixing errors in your code. JavaScript errors appear in the browser's Console (DevTools). You can also pause execution and inspect variables using breakpoints.
- โขOpen DevTools: F12 (or Cmd+Option+I on Mac) โ Console tab
- โข
console.log(value)โ print any value to the console - โข
console.error(msg),console.warn(msg)โ coloured output - โข
console.table(array)โ display arrays/objects as a table - โขRed error messages show the file, line number, and error type
- โขBreakpoints: click a line number in Sources tab to pause execution
- โข
debugger;statement in code pauses execution (same as a breakpoint)
Think of it like spectator mode in a game
Spectator mode in Minecraft lets you fly through the world and see what's happening without changing anything. A breakpoint does the same for your code โ execution freezes mid-run and you can inspect every variable's value at that exact moment.
How It Works
- โข1. Open DevTools โ Console to see errors and
console.logoutput - โข2. Click the error message to jump to the exact line that failed
- โข3. Add
console.log(variableName)before the suspect line to inspect values - โข4. In the Sources tab, click a line number to set a breakpoint
- โข5. When execution hits the breakpoint, it pauses โ hover variables to see their values
- โข6. Use Step Over (F10), Step Into (F11), Step Out (Shift+F11) to advance line-by-line
Real-World Examples
- โขA login form not submitting โ console shows
TypeError: Cannot read properties of undefined - โขAn API fetch returning wrong data โ
console.log(response)reveals the actual shape - โขA counter not incrementing โ breakpoint shows the variable was never re-assigned
- โขSpotify's engineers use breakpoints daily when player state gets out of sync with the UI
- โขTikTok's team uses
console.table(posts)to verify feed data before rendering
Key Facts
- โขThe most common JS errors:
TypeError(wrong type),ReferenceError(undefined variable),SyntaxError(typo in code) - โขChrome DevTools has a network tab showing every API request โ invaluable for fetch debugging
- โขYou can run JS directly in the Console: type any expression and press Enter
- โขThe
debugger;statement only pauses if DevTools is open โ safe to commit temporarily
Watch Out!
Remove all console.log() and debugger; statements before shipping to production. They slow things down and expose your internal data to users who open DevTools. Use a linter rule (no-console) to catch forgotten logs.
Remember
F12 โ Console = your best friend. Read the red error message first โ it tells you the type, file, and line. Add console.log() around the problem to trace values.
What You Learned
- โขDevTools Console shows errors and
console.logoutput with file/line info - โขBreakpoints pause execution so you can inspect variable values mid-run
- โขUnlocks: finding any bug faster, understanding complex control flow, confident production code
Key Facts
- โThe most common JS errors:
TypeError(wrong type),ReferenceError(undefined variable),SyntaxError(typo in code) - โChrome DevTools has a network tab showing every API request โ invaluable for fetch debugging
- โYou can run JS directly in the Console: type any expression and press Enter
- โThe
debugger;statement only pauses if DevTools is open โ safe to commit temporarily
Real-World Examples
Remember
F12 โ Console = your best friend. Read the red error message first โ it tells you the type, file, and line. Add console.log() around the problem to trace values.
Quick Quiz
What is debugging?