I came across a snippet of JavaScript that seems to compile even though it's missing a semicolon between the `node.getLispExpression()` call and the closing curly brace. I understand that JavaScript has automatic semicolon insertion (ASI), but I thought that needed a newline character to trigger it. Can anyone explain how this code is working without throwing an error?
4 Answers
Just remember, a closing curly brace indicates the end of a block or function, which also gives JavaScript the signal to insert a semicolon. As for the lombok lost on semicolons, it can be annoying, but honestly, once you get the hang of it, you’ll find it’s not too problematic.
In JavaScript, the automatic semicolon insertion can happen in more situations than just when there's a line break. There's a rule that if the next token is a closing curly brace `}`, a semicolon gets inserted before that. So, even without a newline, the absence of a semicolon before a `}` doesn't break the code. It's a bit tricky, but that's how it parses! You can read more about it in the MDN documentation on automatic semicolon insertion.
Good point! I found that if there’s a closing curly brace right after a statement, JavaScript will automatically insert the semicolon for you. That's why your code runs fine. If you're interested, check out some resources on Google about JavaScript's automatic semicolon insertion rules. It's surprisingly fun to learn how flexible the language can be!
You might be confusing the requirements for semicolons. They aren't always mandatory. In this case, there’s only one statement on that line due to the arrow function. The confusion often arises because of how arrow functions work. If you replaced `(node) => {return node.getLispExpression()}` with a named function, it might feel cleaner and less jarring.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically