Free tools Windows power users keep installed
One-click scans. No signup required.
Do you need semicolons in JavaScript? Not after every statement: ECMAScript allows many statement-ending semicolons to be omitted, using automatic semicolon insertion (ASI). But ASI is a set of grammar rules, not a rule that every newline ends a statement. Use the formatter and lint configuration already established by your project, and learn the line breaks that can change how code is parsed.
What automatic semicolon insertion does—and does not do
Ecma International’s ECMAScript 2026 specification, §12.10, says: “Most ECMAScript statements and declarations must be terminated with a semicolon.” It also permits semicolons to be omitted in specified situations. The parser inserts them when grammar and token boundaries meet the specification’s rules—for example, when a token cannot fit the grammar and a line terminator, closing brace, or end of input provides the relevant boundary, or when a restricted production forbids a line break.
As an Amazon Associate I earn from qualifying purchases.
There are exceptions: insertion does not happen if it would create an empty statement or become one of the two separators in a for header. So a newline is not, by itself, a reliable statement terminator. The same source can be parsed differently than its visual layout suggests.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Where omitting semicolons can change the result
A newline after return ends the return
function getValue() {
return
{ answer: 42 }
}
This function returns undefined. The line terminator after return causes a semicolon to be inserted, so the object literal is not the return value. Put the expression on the same line: return { answer: 42 }. Similar restricted line-break rules apply to throw and yield; keep the intended expression on the same line as the keyword.
#1 Best Overall
A leading parenthesis or bracket can continue the previous expression
const settings = {}
(function () {
configure(settings)
})()
The next line begins with (, so it can be parsed as continuing the preceding expression rather than starting an independent statement. In this case, the parser can treat the code like a call on the object. A line beginning with [ can create a similar continuation hazard.
With explicit semicolons, terminate the assignment: const settings = {};. In a semicolon-free style, a defensive leading semicolon separates the expressions:
Rank #2
const settings = {}
;(function () {
configure(settings)
})()
ESLint documents this kind of ambiguity in its semi rule guidance, and Standard Style documents the leading-semicolon convention in its semicolon rules.
Other line breaks have special rules
Keep postfix ++ or -- with its operand; put an expression on the same line as return, throw, or yield; keep a label with break or continue; and keep arrow parameters with => and async with the function or method token that follows. Depending on the construct, a line break in these positions can force insertion or cause a syntax error. The specification’s ASI rules define the behavior.
How the two styles compare
| Consideration | Explicit semicolons | Omitting statement-ending semicolons |
|---|---|---|
| Statement boundaries | Marks endings visibly, which can make boundaries easier to scan. | Relies more on readers and tools to recognize where grammar ends one statement and begins another. |
| Punctuation | Adds a consistent marker after statements that require termination. | Reduces punctuation, but may need a leading defensive semicolon before certain next-line expressions. |
| ASI hazards | Helps separate adjacent statements, but does not make a newline after return safe. |
Needs care around continuation characters such as ( and [, and the same restricted line-break rules still apply. |
| Project consistency | Works when the formatter and lint rules agree on this convention. | Also works when the formatter and lint rules agree; Standard Style documents this policy. |
Neither convention is inherently faster or more correct at runtime. The meaningful difference is readability and tooling consistency; correctness depends on whether the code parses as intended. The cited guidance establishes available style policies, not a universally best choice.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Choose a convention your tools can enforce
Prettier
Prettier documents semi: true as its default. Setting semi: false omits statement-ending semicolons while retaining leading semicolons on lines where they protect against ASI problems. See Prettier’s semicolon option and its rationale for semicolons.
Rank #4
ESLint
The core ESLint semi rule documents always and never conventions, but the rule page says it was deprecated in ESLint v8.53.0 and directs users to the corresponding rule in @stylistic/eslint-plugin. Check the installed ESLint version, plugin, and project configuration before changing rule syntax. ESLint’s recommended configuration also enables no-unexpected-multiline, which disallows confusing multiline expressions; see the semi documentation.
Standard Style
JavaScript Standard Style’s semicolon policy omits statement-ending semicolons and uses a leading semicolon where needed to prevent an expression from continuing the previous one.
Quick Recap
Best Value
A practical way to decide
- Check the repository first. Look at existing files and the formatter and lint configuration; matching the project avoids noisy formatting changes and conflicting rules.
- Let one formatter own the output. Prettier supports either choice through its
semioption. Avoid configuring a linter to demand output that the formatter immediately rewrites. - Keep line-sensitive constructs together. In particular, do not put a line break after
returnwhen the next expression is its intended value, and review lines starting with(or[. - Review intentional exceptions. If a defensive leading semicolon appears in an otherwise semicolon-free file, it separates expressions; do not remove it without checking how the preceding line parses with the next one.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




