4
Spent 3 hours chasing a missing semicolon in JavaScript
Last night I was working on a simple todo list app for a class project. I kept getting this weird error that said 'unexpected token' but the console wouldn't tell me where. After 3 hours of staring at my code, I finally found a missing semicolon on line 47. Has anyone else spent way too long on a tiny typo like that?
2 comments
Log in to join the discussion
Log In2 Comments
hugotaylor10d ago
Oh man I've been there... I once spent a whole evening hunting down a comma that was supposed to be a period in a config file. What I do now is just run my code through a linter before even trying to test it, catches all those stupid little typos before I can waste time on them.
5
robinp8910d ago
The missing semicolon thing is rough but a linter won't always catch it if your JS is minified or you're using a weird setup. Also, semicolons are actually optional in JavaScript now with automatic semicolon insertion (ASI). The real issue is probably that you had a line break where ASI couldn't figure out what you meant, like if you started a line with a bracket or something. A linter helps, but reading your code line by line from the bottom up is what I do when I'm stuck like that. It forces your brain to stop guessing and actually see each character.
1