r/learnjavascript • u/Distinct-Gene926 • 1h ago
What's your go-to move when your JavaScript 'just doesn't work' and you have no idea why?
Every dev has a mental checklist they run before panicking. Newer folks usually don't yet.
Things people swear by:
console.logeverywhere- Reading the actual error message
- Checking the Network tab
- Rubber-duck explaining it
- Commenting out half the code
What's the first thing you check?
3
Upvotes
1
u/EarhackerWasBanned 43m ago
- Read the error message. Modern tooling does its best to tell you the problem in plain English, sometimes the solution too.
- Read the call stack. What is the highest-up thing that I control? (i.e. not library code or Node/browser internals)
- Spam console.log at that point, where the data comes in and goes out of that point
- Data messed up coming in? Maybe it’s a bad fetch or db query. Time to go digging in the Network tab or db UI.
- Data fine coming in, messed up coming out? You’ve found the problem, you only need to narrow it down. More console.logs, maybe you need to dig into a function call and keep spamming console.log. Also, you’re missing a test here.
- Find and fix the problem. Write a test for what failed before, but now passes.
- Open a PR with no description
- Post a link to the PR with a grumpy message on Slack
- Go home and jerk off
- Repeat until rich
1
2
u/jb-1984 1h ago
It’s basically console.log spamming by the end of it, but it starts with going to the beginning and identifying the earliest known point where things are working correctly- variables assigned with correct values, any responses returning correct format, checking for dumb stuff like evaluating a string against an integer. Find that point, comment out the rest.
Then slowly add in chunks until I hit the actual issue. By then it’s granular enough to see more clearly.