-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Standard
The Airbnb JavaScript Style Guide provides a set of naming conventions for various code elements in JavaScript to maintain a consistent and readable codebase. Here are the naming conventions for different code elements along with examples:
Variables should use camelCase. Descriptive names should be used. Prefix boolean variable names with "is" or "has" for clarity.
- const userCount = 10;
- const hasPermission = true;
- let userName = 'JohnDoe';
Constants should be in UPPERCASE with underscores. They should be descriptive.
- const MAX_USERS = 100;
- const API_KEY = 'your-api-key';
Method names should use camelCase. Descriptive names should be used.
- function calculateTotalPrice() { /* ... */ }
- function getUserInfo() { /* ... */ }
Use lowercase names. Use kebab-case for file names, and underscores for directories in file paths.
- import myModule from 'my-package';
- const modulePath = 'my_directory/my_file.js';
Class names should use PascalCase. Descriptive names should be used.
- class Employee { /* ... */ }
- class HttpRequest { /* ... */ }
Exception names should use PascalCase and end with "Error" to indicate they are errors. Descriptive names should be used.
- throw new ValidationError('Invalid input');
- throw new NotFoundError('Resource not found');