About Lesson
Importance of a Style Guide:
A style guide ensures consistency, readability, and maintainability across your codebase.
Key Style Rules:
1. Variable Naming:
- Use camelCase for variables and functions.
- Use UPPER_SNAKE_CASE for constants.
- Avoid single-character variable names unless meaningful.
Example:
JavaScript
const MAX_HEIGHT = 100;
let userName = "Alice";
2. Braces and Indentation:
- Use two or four spaces for indentation.
- Place opening braces { on the same line as the statement.
Example:
JavaScript
if (isLoggedIn) {
console.log("Welcome back!");
}
3. Semicolons:
Use semicolons to terminate statements.
4. Use const and let:
Avoid var.
Example:
JavaScript
const user = { name: "Alice" };
Real-Life Use Case:
Using a consistent style guide ensures easier onboarding of new developers in a project and prevents common errors.