- Use consistent naming conventions:
- Variables and functions camelCase
- Constants UPPERCASE
- Classes PascalCase
- Organize code with proper whitespace and indentation
- Modularize code into reusable functions and modules
- Add comments explaining sections of complex code
- Use strict equality checks (===) for comparisons
- Declare variables with let/const instead of var
- Avoid globals by declaring variables in smallest scope possible
- Cache DOM queries instead of repeating them
- Use event delegation for efficient event handling
- Validate input data and escape output
- Practice DRY (Don't Repeat Yourself) principles
- Remove unused code and debug statements
- Use linting tools like ESLint to automatically enforce standards
- Follow style guide recommendations (e.g. Airbnb)
- Use Git for version control and collaboration
- Keep scripts small and focused on single task
- Avoid anti-patterns like excessive nesting, complex logic etc