V
27

TIL a single missing semicolon cost me 4 hours of debugging

I was working on a simple JavaScript function last night to sort an array of numbers. The code looked fine to me, no red underlines in VS Code, no errors in the console at first glance. But the output kept coming back in the wrong order no matter what I tried. After about 2 hours I started checking line by line, even rewrote the whole function from scratch. Turns out I forgot a semicolon after a variable declaration way up top, which broke the next line's logic in a weird way. It took another 2 hours before I finally noticed it while squinting at my screen at 1 AM. Has anyone else wasted a whole evening on something as tiny as a missing character?
3 comments

Log in to join the discussion

Log In
3 Comments
torres.blair
Wait reading this made me actually gasp out loud. A lowercase L instead of a 1? That is genuinely terrifying because they look almost identical in most fonts. I would have probably tossed my laptop out the window if that happened to me on a Saturday. How did you even end up catching that? Did you just happen to glance at it the right way or did you have to go full detective mode with a magnifying glass on the screen. That kind of bug makes me want to switch to a monospace font and turn on character highlighting for every single file I open.
8
tessap73
tessap7313d ago
Oh man, I feel this SO HARD. I spent a whole Saturday once trying to figure out why my Python script would crash randomly, only to find I used a lowercase 'l' instead of a 1 in a variable name. Those tiny mistakes are the WORST because your brain just skips right over them every time.
6
phoenixk64
phoenixk6413d ago
Yeah @tessap73 the letter vs number thing gets me too. What worked for me was turning on strict mode in JavaScript and using a linter that catches those missing semicolons as actual errors instead of just warnings. I set up ESLint to flag any missing semicolons as problems and it cut down on these stupid bugs by like 90 percent. Also started using prettier to auto-format on save so I dont even have to think about it anymore. Now when I see a weird bug that shouldnt exist I just let the linter scream at me before I even start debugging manually.
5