- Use meaningful and descriptive names for variables, functions, and classes.
- Use CamelCase for classes, functions and variables.
- Use uppercase for constants.
- Use
const
for variables that are not reassigned andlet
for variables that are reassigned.
const myVar = "foo";
let myOtherVar = "bar";
- Use === and !== for equality and inequality comparisons.
if (myVar === myOtherVar) {
console.log("They are equal!");
} else {
console.log("They are not equal!");
}
- Use arrow functions for anonymous functions.
const myFunc = () => {
console.log("Hello World!");
};
- Use async/await for asynchronous code.
const myAsyncFunc = async () => {
await someAsyncOperation();
console.log("Done!");
};
- Keep code DRY (Don't Repeat Yourself).
- Avoid long functions or methods.
- Avoid magic numbers or hard-coded values.
- Write code that is easy to read and understand.
- Follow established conventions and patterns within the codebase.
By following these guidelines, we can create code that is consistent, maintainable, and easy to read. If you have any questions or suggestions for improving the style guide, please reach out to the project maintainers.