David Leppik
1 min readSep 19, 2022

--

JavaScript was intended to be used for single lines of logic within HTML tags, with a few extra lines in a script tag.

It originally had a Lisp syntax (parentheses, no semicolons) but was quickly converted to a Java-like syntax, and ASI was part of that original hack.

As its speed and capabilities grew, there was an awkward growth stage as developers learned to use it for bigger tasks, and work around the original design decisions that no longer made sense, such as truthiness and automatic string-to-number conversion. (Convenient for form validation, treacherous everywhere else.)

That was when the semicolon debate began. There’s no consensus on whether semicolons are a language feature or a necessary hack for fitting two lines in an HTML tag. There is no “meant to be” argument. JavaScript wasn’t invented along with a style guide like Java.

I have no strong opinion either way. JavaScript is designed to work both ways, and that in itself causes bugs in certain edge cases, such as a multiline return statement. But omitting or including optional semicolons makes no difference. If your team also works in Java or C#, use them. If the team uses Python, Ruby, or Kotlin, don’t.

--

--

No responses yet