---
name: javascript-naming-conventions
source: https://app.decimal.ai/s/javascript-naming-conventions@1/SKILL.md
source_sha256: 1beea4b77a00
---

# JavaScript / TypeScript naming conventions

## Contract

Every identifier in JS/TS code carries a fixed case determined by WHAT it names, not by
taste. Apply these whenever you declare a class, type, function, variable, constant, enum,
or boolean in JavaScript or TypeScript source.

## Rules

1. **Types are `UpperCamelCase` (PascalCase).** Classes, interfaces, `type` aliases, enum
   type names, and React components: first character uppercase, no underscores, no hyphens.
   `class BankAccount`, `interface UserProfile`, `type ClickHandler`, `enum LogLevel`,
   `function ProfileCard()` (a component).

2. **Callables and bindings are `lowerCamelCase` (camelCase).** Functions, methods, local
   variables, parameters, object properties, and instances: first character lowercase.
   `function calculateTotal()`, `const activeUsers = []`, `deposit(amount)`, `let retryCount`.

3. **Deeply-immutable module-level constants are `CONSTANT_CASE`.** All uppercase letters,
   words separated by single underscores (a.k.a. SCREAMING_SNAKE_CASE). Reserve this for a
   value that is module/exported scope AND never changes AND whose nested contents are
   trusted never to change: `const MAX_RETRY_COUNT = 5`, `const DEFAULT_TIMEOUT_MS = 30000`.

4. **Enum members are `CONSTANT_CASE`** — regardless of language. The enum type is PascalCase,
   its members all-uppercase: `enum LogLevel { DEBUG, INFO, WARN, ERROR }`.

5. **Boolean names start with a predicate prefix: `is` / `has` / `can` / `should`** (also
   `did` / `will`). Applies to boolean variables, properties, and boolean-returning fields:
   `isEnabled`, `hasChildren`, `canRetry`, `shouldFlush`. A bare adjective/noun (`enabled`,
   `children`) reads as a value, not a flag.

6. **Functions are named verb-first (verb + noun).** An action gets a verb: `fetchOrders`,
   `renderChart`, `validateInput`, `handleClick`. A bare noun (`order`, `input`) names a
   value; a function that DOES something must lead with what it does. Boolean-returning
   predicates use `is`/`has` + noun or a verb like `validate`.

7. **Descriptive over abbreviated.** Full words that reveal intent; the only always-fine
   short forms are `id`, `url`, `api`, and a loop index `i`/`j`. Avoid `calc`, `usr`, `btn`,
   `tmp`, and lone letters otherwise.

## Worked examples (base default → conforming)

- Config constant:
  `const requestTimeout = 5000;` → `const REQUEST_TIMEOUT_MS = 5000;`
- Enum members:
  `enum Color { Red, Green, Blue }` → `enum Color { RED, GREEN, BLUE }`
- Boolean flag:
  `let loading = true;` → `let isLoading = true;`
- Boolean property:
  `{ visible: false, admin: true }` → `{ isVisible: false, isAdmin: true }`
- Action function named as a noun:
  `function invoice(cart) { ... }` → `function generateInvoice(cart) { ... }`
- Class casing:
  `class shopping_cart {}` → `class ShoppingCart {}`
- Local mutable binding stays camelCase (NOT a constant):
  `const CART_ITEMS = [];` → `const cartItems = [];`

## Edge cases & exceptions

- **`const` is not the same as "constant."** A `const` that binds a mutable object/array, or
  that is function-local, is NOT CONSTANT_CASE — it stays camelCase (`const session = openSession()`).
  Reserve CONSTANT_CASE for deeply-immutable module-level values.
- **React:** components are types → PascalCase (`UserMenu`); hooks are functions → camelCase
  and start with `use` (`useAuth`).
- **Acronyms:** keep them consistent project-wide, but this convention does NOT dictate their
  internal casing — both `httpClient` and `HTTPClient` styles exist; just don't mix.
- **Privacy:** use `#field` for true private fields; do not rely on a leading underscore.

## Do / Don't

- Do `interface OrderLine` — Don't `interface orderLine` or `interface Order_Line`.
- Do `const MAX_UPLOAD_BYTES = 10_000_000` — Don't `const maxUploadBytes = 10_000_000` for a fixed module constant.
- Do `enum Direction { UP, DOWN }` — Don't `enum Direction { Up, Down }` or `{ up, down }`.
- Do `const isExpired = ...` — Don't `const expired = ...` for a boolean.
- Do `function sendReport()` — Don't `function report()` for an action.

## Common mistakes (the base model's wrong defaults)

- Casting module-level config values in camelCase instead of CONSTANT_CASE.
- Casting enum members as PascalCase or lowercase instead of CONSTANT_CASE.
- Omitting the `is`/`has`/`can`/`should` prefix on boolean identifiers.
- Naming an action function with a bare noun.
- Over-abbreviating (`calcTot`, `usrSvc`) instead of full descriptive words.

## Quick checklist

- Type (class/interface/type/enum/component) → PascalCase.
- Function / method / variable / parameter → camelCase.
- Module-level immutable constant → CONSTANT_CASE.
- Enum member → CONSTANT_CASE.
- Boolean → is/has/can/should prefix.
- Function → verb-first (verb + noun).
- No cryptic abbreviations (id/url/api excepted).
