Indentation Levels for JavaScript

Question
What’s the recommended indentation level for JavaScript code?

Answer
There’s no universal agreement, but my recommendation is four spaces per indentation level.

Comments
Here are the indentation rules from notable JavaScript style guides:

• Crockford’s Code Conventions for JavaScript recommends 4 spaces for indents.
• The Dojo Style Guide recommends tabs (set to 4 spaces) for indents.
• The Google JavaScript Style Guide recommends two spaces for indents.
• The jQuery Style Guide recommends indentation with tabs.

Whichever style you adopt, be sure not to mix them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s