V
28

Spent 6 hours debugging a missing semicolon in JavaScript last night

I was working on a simple function that adds two numbers together and it kept throwing errors, but it turned out I just forgot one semicolon on line 12, has anyone else had a tiny syntax error waste a whole evening?
4 comments

Log in to join the discussion

Log In
4 Comments
johnson.river
Oh man, six hours is brutal for a semicolon. I feel your pain though, I once spent a whole Friday night tracking down a missing curly brace in a loop that just made my whole site crash silently. The worst part is when you finally find it and you just sit there staring at the screen like, "that's it?" It's like the universe is testing your patience with invisible punctuation or something. Glad you figured it out, those tiny mistakes are the sneakiest!
8
samrodriguez
Wait actually I gotta push back a little on the semicolons being optional thing. They're only optional in JavaScript if you really know the automatic semicolon insertion rules, and even then it's risky. I used to think they were totally optional too until I learned about how ASI actually works and realized it doesn't always insert them where you'd expect. Like if you start a line with an array bracket or a parenthesis, it won't add a semicolon before it and suddenly your code breaks in ways that make zero sense. So yeah technically you can skip them but you're basically playing roulette with your code. Better to just put them in and never have to think about it.
1
iris_schmidt
Haha totally feel you on that one lol. I once had a production bug where a line starting with a bracket broke everything because ASI didn't add a semicolon, spent like three hours debugging before I realized what was up.
3
linda_reed
Used to be one of those people who thought semicolons were optional in JS and just shrugged when stuff broke. Then I spent four hours hunting a bug that turned out to be a missing semicolon in a minified file, and @johnson.river is totally right about that staring at the screen feeling. Now I'm religious about putting them in before even running the code, because apparently I learn best through pain and wasted nights. Makes you wonder how much time we've all collectively lost to invisible punctuation over the years.
3