Code Style
Naming Conventions
- •Variables/Functions: camelCase (
fetchUser,isValid) - •Classes/Components/Types: PascalCase (
UserProfile,SearchInput) - •Constants: SCREAMING_SNAKE_CASE (
MAX_RETRY_COUNT,API_BASE_URL) - •Files: Match the primary export
- •Booleans: Use
is,has,should,canprefixes (isLoading,hasError) - •Event handlers:
handleprefix for handlers,onprefix for props
Functions
- •Single responsibility — do one thing well
- •Limit parameters to 3; use an options object for more
- •Prefer pure functions; isolate side effects
- •Use early returns to reduce nesting
Comments
- •Explain "why", not "what" — the code shows what, comments explain intent
- •Delete commented-out code; version control exists
- •Use JSDoc for public APIs and complex functions