Formatting your code

Spaces and line breaks matter.

Not only do they keep your code organized and easy to read, but there are standards to follow which allow you to merge code with other developers. If you don't follow them, you'll be causing a lot of problems when you work together.

Tabs vs Spaces

The tab character can be problematic as it may be behave differently per system.

Two spaces is the most commonly used indentation.

Your IDE can be configured to use 2 spaces when you hit tab.

https://www.alpharithms.com/tabs-vs-spaces-the-timeless-debate-581511/

Syntax Highlighting

You can configure your editor to highlight the code you're working on, showing syntax in a different color to help you read the logic.

Linting

You can also set up your editor to check the code and flag errors for you to resolve.

Pretty Print

Reformatting your code is sometimes called pretty printing.

https://prettier.io/

Coding Standards

Many projects establish coding standards to define how to write consistent code, such as tabs vs spaces and where to put line breaks. These rules help developers on big projects work together and avoid reviewing patches with extra changes due to curly braces moving around.

https://github.com/airbnb/javascript

.editorconfig

A file in your project root that defines tab indentation and other formatting options that works across popular IDEs.

https://editorconfig.org/

Level
Topics