DEV Community

JS Bits Bill
JS Bits Bill

Posted on • Edited on

3 2

An alternative to using logs: debug()

The Chrome console includes a helper method called debug that will pause execution in the debugger on the first line of a provided function.

function greeting(msg) {
  console.log(msg);
}

// Debug the greeting function whenever it gets called
debug(greeting);

// Once greeting is called the Sources panel in DevTools will automatically open
greeting('Hello World!');
Enter fullscreen mode Exit fullscreen mode

When using debug, the breakpoint is added to the function definition and paused regardless of where it is called. So this is just a quick way to see if and how a function is being called without having to add your own logs to it or manually track it down in the Sources to add a breakpoint! ⚡


Check out more #JSBits at my blog, jsbits-yo.com. Or follow me on Twitter!

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay