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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay