0% found this document useful (0 votes)
1 views2 pages

JavaScript Coding Standards

This document outlines JavaScript coding standards based on Airbnb and Google style guides, covering naming conventions, formatting, variable declarations, functions, and best practices. Key points include using camelCase for variables, 2-space indentation, and preferring arrow functions and strict equality. It serves as a reference for maintaining consistent code quality within teams.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

JavaScript Coding Standards

This document outlines JavaScript coding standards based on Airbnb and Google style guides, covering naming conventions, formatting, variable declarations, functions, and best practices. Key points include using camelCase for variables, 2-space indentation, and preferring arrow functions and strict equality. It serves as a reference for maintaining consistent code quality within teams.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Coding Standards

Based on Airbnb / Google JavaScript style guide conventions

1. Naming Conventions
Element Convention

Variables / functions camelCase (e.g., userCount, getData())

Classes / Components PascalCase (e.g., UserProfile)

Constants UPPER_SNAKE_CASE for true constants (e.g., MAX_RETRIES)

Private class fields leading underscore or # private fields (e.g., #token)

Files kebab-case or camelCase depending on team convention

2. Formatting
• Use 2-space indentation (most common community standard).

• Always use semicolons to terminate statements.

• Prefer single quotes for strings unless interpolation is needed (then use template literals).

• Limit line length to ~80–100 characters.

• Use a formatter like Prettier to enforce formatting automatically.

3. Variable Declarations
const maxRetries = 3; // use const by default

let attempts = 0; // use let only when reassignment is needed

// avoid var entirely

4. Functions
• Prefer arrow functions for callbacks and short functions.

• Use default parameters instead of manual undefined checks.

• Keep functions small and focused on a single responsibility.

• Use async/await over raw Promise chains for readability.


4. Example
const fetchUser = async (id) => {

const response = await fetch(`/api/users/${id}`);

if (![Link]) throw new Error('User not found');

return [Link]();

};

5. Best Practices
• Use strict equality (===, !==) instead of loose equality.

• Avoid global variables; use modules (import/export).

• Destructure objects and arrays where it improves readability.

• Handle errors explicitly — never leave empty catch blocks.

• Run ESLint with a shared config (Airbnb, Standard, or Google) plus Prettier in CI.

Compiled as an original summary of widely-followed community and vendor style guidelines, for internal reference use.

You might also like