TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you debug your JavaScript?

2 pointsby deepanchorabout 4 years ago
I’m getting tired of using console.log all the time, so I’ve finally decided to learn how to debug frontend code the proper way.<p>What are your favourite javascript debugging tips and tricks?

2 comments

forgotmypw17about 4 years ago
My favorite &quot;secret weapon&quot; for JS debugging is sprinkling my .js templates with statements like this:<p><pre><code> &#x2F;&#x2F;alert(&#x27;DEBUG: FunctionName() begins, param1 = &#x27; + param1 + &#x27;; param2 = &#x27; + param2); </code></pre> My JS injector has a &#x27;debug&#x27; setting, which rewrites all of those statements into one of: console.log(), document.title=(), or confirm(), the latter of which stops appearing after I press &#x27;No&#x27; or &#x27;Cancel&#x27;.<p>When not debugging on a modern browser with debugging tools like IE6+VS, Firefox, Opera, Safari, or Chrome, it is a real time-saver to be able to toggle those messages, kind of like a poor man&#x27;s breakpoint.<p>(I develop retro sites which are designed to live up to the &quot;any browser&quot; dream, so I test with NN2+, IE3+, and Opera3+, in addition to Lynx, w3m, Links, Dillo, NetSurf etc., not to mention the mainstream FF, Chrome, Edge, Safari.)
austincheneyabout 4 years ago
I wrote an error handling utility for my application which is helpful.<p>All my functions are uniquely named against a standard naming convention which helps with stack traces.<p>For actual debugging I just sprinkle around some console.log statements to see the flow control leading up to the problem. I have an ESLint rule to warn on console statements which makes for easy cleanup.<p>The hardest part of debugging for me, in a peer to peer app, is that the stack trace isn’t going to align with a flow control divided across a network.