Skip to content

Thoughts on JavaScript style guides

Published on 13 November 2021

When reading this weeks issue of JavaScript Weekly I found a link to Airbnb’s latest JavaScript style guide.

I’ve always thought code style is important, and like everyone else I have my preferences, but ultimately it’s consistency that matters.

Whilst personal preference plays a big part, I think it’s important to justify each rule wherever possible. Airbnb’s guide does a great job of this, for example in relation to function signature spacing:

“Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.”

Today with tools such as Prettier you don’t need to worry so much about following the rules when authoring code as it will be formatted when you save or commit your work.

The real benefit of style guides in my opinion is how they make reading code easier. If the style is consistent across a code base, you spend less time trying to decipher unfamiliar formatting and more time understanding what the code itself is doing.

In conclusion, I strongly recommend having style guides and sticking to them, and using Prettier and ESLint to enforce it. The upfront cost is small so there really are no excuses.

This post is part of a series of posts in which I write and publish a blog post every day throughout November 2021. There are no constraints on the project and the posts don’t neccissarliy have any connection to each other.

See all of the posts in the 30 days of writing project.