October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Why Dev Teams Still Fight Over Semicolons

Both semicolon-heavy and semicolon-light JavaScript are supported. Learn how ASI actually works, where omitted semicolons break expectations, and how teams can enforce one consistent convention.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript teams fight over semicolons because both styles are valid, but neither is consequence-free. ECMAScript defines automatic semicolon insertion (ASI), so many statement-ending semicolons may be omitted. ASI follows grammar rules, however—not the shortcut “every newline ends a statement.” The practical solution is to choose one convention for the repository and enforce it with formatting and linting.

Are semicolons required in JavaScript?

Not always. The ECMAScript specification permits programs to be written with very few semicolons and defines when the parser inserts one automatically. Some statements and declarations require termination, while others can rely on ASI when the grammar cannot continue the statement across a line break.

As an Amazon Associate I earn from qualifying purchases.

That means a newline is not itself a statement terminator. JavaScript first tries to parse the lines as one valid statement. Only when the grammar reaches a restricted point—or a line break would otherwise make the program invalid—does ASI insert a semicolon.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A newline can end a simple statement

const width = 10
const height = 20

This is normally parsed as two declarations because the second const cannot continue the first declaration.

A newline can also continue the previous expression

const items = [1, 2]
[3, 4].forEach(printItem)

Without an explicit semicolon, the second line can be interpreted as a bracket access on the first expression—effectively continuing [1, 2]—rather than beginning an independent expression. The result is not the two operations the author intended.

Some grammar positions are especially important

function getConfig() {
  return
  {
    mode: "safe"
  }
}

A line break immediately after return triggers ASI, so this function returns undefined; the object literal is a separate statement. Keeping the returned expression on the same line avoids that rule.

Why semicolon-free code needs defensive habits

A no-semicolon convention is not simply “delete every semicolon.” The beginning of a line matters because tokens such as (, [, a template literal, +, -, *, /, ,, and . can be parsed as a continuation of the previous expression.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, a semicolon-free style commonly writes a defensive semicolon before an immediately invoked function or a line-starting array expression:

const setup = getSetup()
;(function () {
  setup()
})()

const first = getFirst()
;[first, second].forEach(useValue)

The leading semicolon protects the new expression if the preceding line could legally continue into it. StandardJS documents this approach as part of its no-semicolon convention. It is a convention for avoiding ambiguous line starts, not proof that every ASI edge case is harmless.

Explicit and semicolon-light styles compared

Question Explicit semicolons Semicolon-light
Statement boundaries Terminators are visible at statement ends. Most boundaries are supplied by ASI and line structure.
Parser knowledge Developers still need to understand ASI for exceptions such as return followed by a line break. Developers must pay particular attention to line-start tokens and ASI’s grammar rules.
Formatter support Prettier’s semi: true prints semicolons at statement ends. Prettier’s semi: false prints only defensive semicolons needed at potentially hazardous line starts.
Lint and style-guide support Supported by common lint configurations. StandardJS specifies a no-semicolon rule with defensive exceptions.
Review impact Reviewers see explicit terminators when scanning code. Reviewers must recognize where ASI applies and whether a line start is safe.

There is no established universal winner for readability, defect rates, or developer productivity. The available guidance demonstrates that current tooling supports both choices.

Why the argument keeps returning in code review

Personal habits look like technical rules

Developers often learn one style first and experience it as “normal.” Because both styles compile in many everyday cases, each side can point to working code as evidence. That is preference, not a language requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ASI is easy to oversimplify

“JavaScript adds semicolons at newlines” is inaccurate. ASI is conditional, and a line break may be ignored when the combined tokens form a valid expression. Conversely, an insertion can occur in a place that changes the program’s meaning, as with a line break after return.

Mixed style creates a real maintenance problem

Alternating between conventions forces every author and reviewer to renegotiate formatting. The cost is not the punctuation itself; it is repeated disagreement and inconsistent automated output.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to settle the decision for a repository

  1. Choose the convention explicitly. Decide whether statement-ending semicolons are printed, or whether the project follows a semicolon-light style with defensive line-start semicolons.
  2. Put the choice in formatter configuration. For Prettier, set semi: true or semi: false in the repository configuration.
  3. Align lint rules. Configure the linter or adopt a guide such as StandardJS so lint and formatting do not issue contradictory instructions.
  4. Run the tools automatically. Use pre-commit checks and continuous integration so new files are formatted consistently before review.
  5. Document the few semantic exceptions. Whichever style you select, explain line breaks after return, throw, and similar restricted positions, plus defensive semicolons before ambiguous expression starts.
  6. Stop reopening the preference debate. Reconsider the policy only when the project changes its formatter, lint stack, or language constraints.

Example Prettier choices

// Explicit terminators
{
  "semi": true
}

// Semicolon-light output
{
  "semi": false
}

In a semicolon-light project, inspect generated or manually edited code that begins a line with a bracket, parenthesis, template literal, arithmetic operator, comma, or dot. In an explicit-semicolon project, keep the formatter authoritative rather than hand-editing individual files to satisfy personal taste.

What should an individual developer use?

For a new personal project, either convention is defensible. Choose semicolons if visible statement endings make the code easier for you to scan. Choose semicolon-light formatting if you prefer less punctuation and are willing to follow its line-start rules. For an existing team codebase, use the repository’s configured formatter and lint policy—even when your personal preference differs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The practical verdict

Semicolons are optional in many JavaScript statements, but the consequences of omission are governed by precise parsing rules. The team-level answer is therefore procedural: select one style, configure it once, run it automatically, and teach the small number of ASI cases that affect correctness. That ends a recurring taste argument without pretending the language has declared one side technically superior.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.