Course contentsShow
← Web Development
Lesson 2263 of 2,98241. Debugging TechniquesFree lesson

Function Breakpoints with debug()

Use the debug() function in the console to break whenever a specific function is called programmatically.

Function Breakpoints with debug()

You'll learn how to pause JavaScript execution whenever a specific function is called, without manually finding its code in the Sources panel.

The Core Idea

The debug() function is a console utility that lets you set a breakpoint on any function by simply passing the function's name as an argument. When that function is called anywhere in your codebase—even in minified or third-party code—execution will pause automatically, just as if you'd set a traditional breakpoint at the function's first line.

Think of debug() as placing a "tripwire" on a function. You don't need to know where the function is defined or hunt through multiple files. You just tell the debugger, "Hey, stop me whenever this function runs."

How It Works

In the console, type:

debug(functionName)

Replace functionName with the actual function reference (not a string). From that moment on, every time that function executes, the debugger will pause, and you can inspect the call stack, variables, and context.

To remove the breakpoint:

undebug(functionName)

When to Use It

  • You suspect a function is being called unexpectedly or too frequently
  • You want to debug library or framework functions without digging through source maps
  • You need to trace who's calling a particular utility function
  • You're debugging event handlers or callbacks where the function reference is known but its location isn't

Key Takeaway: debug(functionName) programmatically sets a breakpoint on any function, pausing execution whenever it's called—perfect for tracking down elusive function calls without manually locating code.