DEV Community

Discussion on: IIFEs in JavaScript and how to avoid this common mistake

craigmc08 profile image
Craig McIlwrath

It seems quite inconsistent to just use a semicolon in this specific case and no where else. In fact, this is a really good example of why you should use semicolons everywhere: to avoid strange errors caused by the implicitly inserted semicolons.

Do you have a reason why you don't use semicolons?

michi profile image
Michael Z Author

I really don't mind the use of semicolons, but personally haven't used them for some time now. It removes some clutter from the code and especially makes chains ([].map.filter etc.) easier to extend.

I am not fully convinced to use semicolons everywhere just for the edge case when a line starts with paranthesis or brackets, but perfectly understand when people do so. There are of course other good reasons to use semicolons.

But you can't switch ASI off, so anyways people have to learn about it. Because even with the use of semicolons you will run into things like this.

    city: 'London'

The above returns undefined because ASI places a semicolon after the return.

Nowadays there are linters and tools like prettier that can really help with these problems.