- Don't try to prematurely optimize your code; keep it readable and understandable
- All code in any code-base should look like a single person typed it, even when many people are contributing to it
- Strictly enforce the agreed-upon style
- If in doubt when deciding upon a style use existing, common patterns
- Don't reinvent the wheel; use styles, templates and code that have already been developed
- Check spelling and grammar in text and code
- Check console output for warnings or errors
- Design with a mobile-first approach
- Build in sufficient testing time
- Test pages and components on all browsers and devices
- Set aside time to write documentation
Use soft tabs with two spaces, they're the only way to guarantee code renders the same in any environemnt. Always be consistent in your use of whitespace, never mix spaces and tabs for indentation. Use whitespace to improve readability.
Tip: configure your editor to “show invisibles” and to automatically remove end-of-line whitespace.
- Use soft tabs with two spaces, they're the only way to guarantee code renders the same in any environment
- Nested elements should be indented once (two spaces)
- Camel-case variable names -
var variableName = 'variable'
- Acronyms should be camel-cased as well. -
- Constants are all caps, seperated by underscores -
- Class names are camel-cased with a leading capital letter. -
- Function names are also camel-cased (with the addition of the acronym rule). -
- Always use single quotes for strings ie.
var person = 'John Doe';
- Avoid inline code for events (eg.
<a onclick="doSomething()" href="#">Click!</a>)
- Run JSLint/JSHint to validate code
- Use dependencies to load scripts
- Don't leave console debugging messages in your production code