I’m against the ASI (Automatic Semicolon Insertion)!

In software development, ASI stands for Automatic Semicolon Insertion and is a feature wide spread in Javascript among the others. This somehow scary name, in simple terms, means that *you are not required to insert a statement terminator semicolon. Let’s see this with a Javscript example:

function formatPercentage(value) {
  const numeric = Number(value ?? 0);
  if (!Number.isFinite(numeric)) return '';
  if (numeric === 0) return '';
  if (numeric === 100) return '100 %';

  return `${(numeric * 100).toFixed(2)} %`;
}


The above is a very well known syntax: every statement is termined by an explicit semicolon symbol. The same function can be rewritten with ASI:

function formatPercentage(value) {
  const numeric = Number(value ?? 0)
  if (!Number.isFinite(numeric)) return ''
  if (numeric === 0) return ''
  if (numeric === 100) return '100 %'

  return `${(numeric * 100).toFixed(2)} %`
}



As you can note, in the above example, there are no semicolon. Since Javscript is a language that requires the same C/Java basic syntax, the semicolon is automatically inserted for you by the parser. Is this feature useful?

Quite frankly, I believe this is one of the most useless feature in any programming language!

According to me, ASI has the following drawbacks;
  • no clear and visible indication of the statement termination;
  • possibility of mixed approaches (e.g., due to copy and paste).
In fact, the above piece of code could have been rewritten with a mixed approach:

function formatPercentage(value) {
  const numeric = Number(value ?? 0);
  if (!Number.isFinite(numeric)) return '';
  if (numeric === 0) return '';
  if (numeric === 100) return '100 %'

  return `${(numeric * 100).toFixed(2)} %`
}


where a few statements have the ; terminator and others have not. This is a clear mess! Imagine a situation where two developers are working on the same codebase, and one prefers the ASI feature while the other does not: you will end up with two different code styles, which is usually a productivity stopper (especially when reviewing code). There is also another problem I see: writing a parser results much more complex since you cannot get for free the termination of a statement.

ASI rules

ASI has rules to work properly, most commonly:
  • the end of a line triggers the semicolon insertion if the next line starts with a control statement (e.g., if) or a function call;
  • a right curly brace indicates a block termination, and a semicolon is added if the leftmost line contains a statement;
  • a semicolon is automatically inserted at the very end of the soucre code.

What about Python?

It is true that Python does not allow a statement terminator, and this approach could seem similar to ASI, but it is not! Python has taken the decision where a statement is terminated by the end of the line, period. Therefore, there is no possibility of having parts of code with a style and another piece with another style.

What about Perl?

Perl and Raku allow particular statements to omit the semicolon terminator: in short, when a statement is the last of a block, it can omit the semicolon terminator because the end of the block (i.e., the curly brace) will automatically terminate the statement too. This is a special behavior that makes writing one liners really cute:

my @positives = map { $_ > 0 } @numbers;

# is the same as
my @positives = map { $_ > 0; } @numbers;


The stament inside the map block can omit the semicolon just to result in shorter code. Please note, once again, that this is not like ASI, it is only because the last statement of a block automatically terminates when the block right curly brace is encountered. While the above behavior seems like one of the ASI rules, it is not: Perl does not insert automatically a semicolon, it simply does not require it as a statement terminator under specific circumstances.

Conclusions

ASI surely has fans among the developers, but quite frankly I believe this a feature that don’t add any particular value to your code. On the other hand, it improves the risks to have different code styles within the same codebase.

The article I'm against the ASI (Automatic Semicolon Insertion)! has been posted by Luca Ferrari on March 26, 2026