Introduction
If your team keeps bouncing between javascript underscore names and camelCase, the problem is not just aesthetics. It shows up in code review friction, inconsistent variable naming, brittle data mapping, and a style guide that nobody trusts when deadlines get tight.
Quick Answer
For most JavaScript web projects, use camelCase for variables, functions, object properties, and internal application code. Keep underscore naming, usually snake_case, at API boundaries, legacy integrations, and data that already arrives that way. The best choice is the one your team applies consistently in a clear javascript style guide.
This decision matters because naming conventions affect readability, collaboration, and long-term maintainability. The right rule is rarely “always underscore” or “always camelCase.” It is usually “match the context, then normalize the codebase so people are not guessing.”
That is the practical lens for this article. You will get a direct comparison of camelCase and underscore naming, where each one fits, how to handle API payloads, and how to standardize naming across a project without turning every change into a style debate.
| Criterion | camelCase | underscore naming |
|---|---|---|
| Cost (as of November 2026) | Zero tooling cost; supported natively in JavaScript and common frameworks | Zero tooling cost; often used where external systems already return snake_case |
| Best for | Application code, functions, variables, hooks, and object properties | API payloads, database fields, legacy systems, and cross-language data contracts |
| Key strength | Matches JavaScript community norms and reads naturally in frontend code | Preserves external naming and can match backend or schema conventions exactly |
| Main limitation | Can feel inconsistent if your backend or database uses snake_case heavily | Feels less native in JavaScript and can reduce readability inside application code |
| Verdict | Pick when your code runs in JavaScript and you control the naming rules. | Pick when you must match external data or a shared system contract. |
Understanding Naming Conventions In JavaScript
Naming conventions are the rules a team uses to name code so the intent is obvious to humans and tools. In JavaScript, that applies to variables, functions, classes, files, object properties, and even generated code. Good naming is not decoration; it is part of the source code design.
There are four styles people mix up most often. camelCase looks like userName. PascalCase starts with a capital letter, like UserProfile. snake_case uses underscores, like user_name. kebab-case uses hyphens, like user-name, and is common in filenames and URLs rather than JavaScript identifiers.
JavaScript community norms strongly favor camelCase for variables and functions. The reason is simple: the style feels natural in most codebases, and it reduces friction when developers move between modules, components, and utility functions. Consistency also speeds code review because the reviewer can focus on logic instead of mentally translating naming patterns.
Good naming reduces cognitive load. If your team can read code without stopping to decode the style, they can spend more time checking behavior, edge cases, and security implications.
That is why consistency usually matters more than any single style choice. A clean Source Code base that uses one coherent naming pattern is easier to maintain than a messy codebase that changes style every few files.
- Variables: use names like
totalAmountorisLoading. - Functions: use names like
fetchUserDataorformatDate. - Classes: use PascalCase, such as
UserProfileService. - API data: keep the contract consistent, even if it is snake_case.
That last point matters in modern web development. A frontend team may prefer camelCase internally while still receiving snake_case from Python, SQL-backed systems, or third-party APIs. The key is to separate the transport format from the application style.
What CamelCase Means In Practice
CamelCase is a naming style where the first word starts lowercase and each additional word starts with a capital letter. In JavaScript, that usually means identifiers like userName, fetchUserData, and isLoadingState. It is the default style most developers expect when reading modern web application code.
CamelCase works well because the word boundaries are easy to scan visually. That matters when your file contains dozens of variables, props, and hooks. A name like currentSessionToken is usually easier to read than current_session_token inside JavaScript code because the style matches the language’s common conventions.
It is also the norm in many frontend workflows. React props, hooks, utility functions, local state variables, and event handlers are usually written in camelCase. That makes the code feel consistent with ecosystem examples and framework documentation from vendors like MDN Web Docs and the official React documentation.
Pro Tip
Use camelCase for anything a developer writes and reads inside the JavaScript application layer. Reserve other styles for boundaries, generated code, or system-specific contracts.
CamelCase also fits well with chained method calls and state logic. When you read userProfile.isActive or formState.hasErrors, the structure is clear and the name still feels native to JavaScript. That is one reason camelCase remains the safest default for most web projects.
- Variables:
userName,retryCount,isLoading - Functions:
fetchUserData,saveDraft,normalizeResponse - Object properties:
displayName,createdAt,lastLoginAt
What Underscore Naming Looks Like
Underscore naming usually refers to snake_case, where words are separated by underscores, such as user_name or fetch_user_data. It is different from leading or trailing underscores, which are often used to signal internal or special-purpose fields, such as _privateValue or error_.
Snake_case is common outside JavaScript. Python uses it heavily, SQL schemas often use it, and many APIs and backend systems return data in that format. In those environments, underscore naming is not strange; it is the expected norm. The problem starts when it is brought into JavaScript without a reason.
In JavaScript, underscore naming is usually more appropriate for compatibility than preference. You may see it in legacy codebases, internal helper fields, generated code, or integration layers that mirror a backend model. For example, a payload from an external service might return order_id, created_at, and shipping_status.
The benefit of underscore naming is that it can preserve exact field names and make data structures easy to compare against source systems. The trade-off is that it can feel less natural inside frontend code, especially when the rest of the codebase is written in camelCase.
That is why underscore naming should be deliberate. Use it when it solves a real integration or contract problem, not because it seems “more structured.” In JavaScript application code, it is usually a boundary style, not an internal default.
When CamelCase Is The Better Choice
CamelCase is the better choice for most standard JavaScript code because it aligns with community expectations and makes the code easier to scan. If you are naming variables, functions, object properties, hooks, or local constants, camelCase should be your default. That is true in both browser code and many Node-based projects.
It also works better with common tooling. ESLint rules, framework examples, and internal team docs usually assume camelCase unless the project has a special reason not to. That alignment matters because developers can move between libraries, modules, and components without re-learning the naming pattern every time.
In frontend work, camelCase is especially valuable because the same file often contains state, event handlers, props, and utility references. A React component might use isModalOpen, handleSaveClick, and selectedUserId. Those names are readable, consistent, and easy to search across the codebase.
It also helps when your code needs to match the style used in documentation examples. If a team is learning from official docs and copying patterns into a project, a camelCase-first naming model reduces translation errors. That is one of the small things that saves time over the life of a codebase.
- React props:
onSubmit,isOpen,userId - Utility functions:
formatCurrency,parseDate,validateEmail - State variables:
formState,errorMessage,isFetching
For teams using a Framework, the safest rule is simple: follow camelCase in application code unless a framework or external API explicitly requires something else. That keeps naming predictable and reduces accidental drift.
When Underscore Is The Better Choice
Underscore naming is the better choice when you need to match a system that already uses snake_case. That is common with REST APIs, GraphQL backends that expose snake_case fields, database column names, exported CSV data, and legacy integrations that should not be renamed at the source. The goal is not to make JavaScript look like another language; the goal is to preserve the contract where it matters.
One practical example is a backend that returns first_name, last_name, and created_at. If the frontend simply mirrors those values everywhere, the UI code becomes harder to read. If the team converts them too early and inconsistently, bugs creep in when data is saved back or sent to another service. In that case, underscore naming belongs at the boundary, not all through the app.
Underscore naming can also help in code generation and data mapping layers. If a tool produces models from a schema, keeping the generated shape intact can reduce debugging time. The same logic applies when a shared contract spans multiple systems and one side already uses snake_case as the canonical form.
That said, use it strategically. A frontend application should usually not spread snake_case into component props, hooks, and local state unless the project standard says so. The more you let boundary naming leak inward, the more you force developers to switch mental models every time they read code.
- Preserve underscore naming at the boundary if the source system owns the contract.
- Transform it into camelCase for internal application models when readability matters.
- Document any exceptions in the project naming rules so no one guesses.
How To Handle API Responses And Data Models
API responses should usually keep their original naming format at the transport boundary, especially when the backend owns the schema. That means if an endpoint returns snake_case, you often receive it as snake_case and convert it before the data enters the rest of the application. This approach preserves interoperability and keeps the API contract stable.
A common pattern is to build a mapping layer that converts snake_case payloads into camelCase domain objects. For example, user_name becomes userName, and created_at becomes createdAt. The application then works with one consistent style, even when the backend, database, or third-party system uses another one.
This is where data mapping becomes important. A transformation utility or adapter can centralize the conversion logic so the rest of the codebase never has to repeat it. That reduces bugs and makes it easier to update field mappings later without touching multiple components.
There is a trade-off. Preserving backend naming can make payloads easier to debug against server logs and database records. Converting to camelCase simplifies frontend code and makes business logic more readable. In most web projects, the second benefit wins once the team has a clear adapter layer.
Note
Keep the transport format and the internal model separate. If your API returns snake_case, normalize it once in a shared adapter instead of rewriting names throughout the UI.
This is especially useful in systems that also use GraphQL or multiple backends. One service may return camelCase, another may return snake_case, and a third may still use database-style fields. A clean mapping layer keeps those differences from leaking into every feature.
Style Consistency Across Teams And Codebases
The real decision is usually not personal preference. It is team convention. A strong naming convention works because everyone follows the same rule set, not because the rule itself is fashionable.
A useful javascript style guide should define naming for variables, functions, components, files, API adapters, and shared utilities. It should also explain what to do with exceptions such as vendor payloads, legacy modules, or generated files. That clarity reduces merge conflicts because developers are not “fixing” each other’s naming choices on every pull request.
Consistency also lowers onboarding friction. A new developer can read one project and know what a variable name, component name, and adapter name are supposed to look like. That matters more in larger teams where the codebase is touched by many people, sometimes across frontend and backend.
When teams share libraries, the naming rules need to be even tighter. Shared components and utilities are reused in different parts of the system, so one inconsistent pattern can spread quickly. The same is true for naming across front end and back end contracts, where interface definitions and payloads should be documented clearly.
- Define a standard for variables and functions.
- Define a separate rule for files and folders.
- Define when API data stays unchanged and when it gets normalized.
- Document legacy exceptions so they do not become accidental standards.
A good style guide is not restrictive. It is a shortcut. It removes the debate from ordinary naming decisions so the team can focus on building the application.
Tooling, Linters, And Automated Enforcement
ESLint is the primary tool most JavaScript teams use to enforce naming rules and catch inconsistent identifiers. It can help ensure variables, functions, and even certain patterns in component names follow the team’s standards. If naming drift is a recurring problem, linting is the fastest way to reduce it.
Prettier plays a different role. It formats code consistently, but it usually does not decide whether a variable should be camelCase or snake_case. That means formatting and naming are related, but they solve different problems. One cleans up structure; the other enforces language rules.
TypeScript adds another layer of control. Interfaces, types, and static analysis make naming issues more visible because the shape of objects becomes explicit. If the team defines a UserProfile interface and then maps API fields into it, the naming structure is easier to verify at compile time. That is useful in larger codebases where a small naming mismatch can break a feature quietly.
Automation should go beyond the editor. CI checks, pre-commit hooks, and pull request review rules can stop inconsistent naming before it lands in main. That matters because human memory is unreliable, especially when multiple teams contribute to the same repository.
- Lint for naming patterns in source files.
- Format with Prettier to keep code visually consistent.
- Type-check object shapes so data transformations stay predictable.
- Gate merges with CI so style drift does not accumulate.
If you need a project-level standard for naming, automation is what makes the standard stick. Without it, the style guide becomes a suggestion instead of a rule.
File Names, Components, And Directory Structure
File names are not the same thing as code identifiers. A project can use camelCase inside the code while still using kebab-case for filenames or PascalCase for React components. Mixing those concerns is where many teams get confused.
In many JavaScript and React projects, components use PascalCase because the component itself behaves like a named UI unit. Variables and functions inside the component still use camelCase. That separation is common, readable, and easy to explain to new contributors. For example, UserProfileCard.jsx might contain userName, handleEditClick, and isExpanded.
File naming conventions depend on the framework and the build system. Some teams prefer kebab-case for filenames because it is easy to scan in directory listings and works well across operating systems. Others prefer camelCase for modules so file names mirror import names. The important thing is not the exact style; it is choosing one pattern and applying it consistently.
Underscore-based file names can be used intentionally, but they should not appear by accident. If a project uses leading underscores to mark partials, private utilities, or generated files, that should be documented. Otherwise, developers end up guessing whether _helpers.js means “internal only” or just “someone liked underscores.”
Warning
Do not let file naming and identifier naming drift into different systems without documentation. A clean code style can still become confusing if folders, components, and functions all follow different rules.
For frontend projects, especially those built with React and similar tooling, a small naming policy for files and directories prevents a lot of friction later. It is one of the easiest standards to formalize early.
Common Mistakes To Avoid
One common mistake is mixing camelCase and underscore naming randomly in the same layer of code. That forces developers to translate mentally every time they move between files. It also makes search and refactoring harder because similar concepts are named in inconsistent ways.
Another mistake is converting names inconsistently between API data, state objects, and UI components. For example, if the API returns created_at, the state uses createdAt, and the UI label still references created_at, your codebase now has three versions of the same idea. That is a maintenance problem waiting to happen.
Leading underscores can also be overused. A single internal field like _cache can be clear. A codebase full of _temp, _newValue, and _resultData can start to feel outdated and harder to navigate. The underscore is not a substitute for a meaningful name.
Short, vague abbreviations are another bad habit. A name like usrNm is not better just because it is shorter. Naming conventions should improve clarity, not hide weak naming behind a style choice.
- Do not mix styles without a documented reason.
- Do not let API field names leak everywhere unchecked.
- Do not overuse underscores as a shortcut for “internal.”
- Do not use style as a substitute for descriptive names.
For teams trying to standardize, the safest path is simple: keep the style boring, the names descriptive, and the exceptions rare.
Practical Decision Framework
Decision framework is the fastest way to settle naming debates without turning them into opinion wars. Start by asking where the identifier lives: inside application code, in external data, in a shared contract, or in a legacy integration. That one question often tells you whether camelCase or underscore naming is the right fit.
Use camelCase by default in JavaScript application code. That includes variables, functions, hooks, local constants, object properties created by your app, and most component-level state. If there is no external constraint, camelCase is usually the most readable and least surprising choice.
Preserve underscore naming at the boundary when the source system already owns the format. Then convert it into internal camelCase models when that improves readability and consistency. This gives you a clean separation between transport data and application logic, which is especially important in web projects with many integrations.
Teams should also codify one standard for each category: code, components, API data, and file names. That prevents “almost consistent” codebases where each folder has its own personality. The rule of thumb is straightforward: optimize for consistency, readability, and developer expectations.
- Identify the context of the name.
- Default to camelCase in JavaScript code.
- Preserve external naming only where the contract requires it.
- Document the exceptions and automate enforcement.
If you are building a frontend app, that framework works better than personal preference. It keeps your naming choices tied to actual technical needs instead of style debates.
Key Takeaway
- CamelCase is the natural default for most JavaScript web projects because it matches developer expectations and common tooling.
- Underscore naming is best used at system boundaries, especially when APIs, databases, or legacy systems already use snake_case.
- A strong javascript style guide should define naming rules for code, components, files, and API adapters separately.
- Automated enforcement through ESLint, TypeScript, and CI prevents naming drift better than manual review alone.
- The best naming convention is the one your team uses consistently, not the one that looks clever in isolation.
Conclusion
For most JavaScript web projects, camelCase is the right default. It fits JavaScript norms, reads cleanly in frontend code, and works well across variables, functions, object properties, and React-style application patterns. When you need to match external data or legacy systems, underscore naming has a place, but it should usually stay at the boundary.
The practical rule is simple: choose one internal standard, preserve external naming only where required, and normalize everything else. That gives you cleaner source code, fewer review arguments, and a codebase that is easier to maintain over time.
Pick camelCase when you are naming JavaScript application code; pick underscore naming when you must match external data, shared schemas, or legacy contracts. Then document the exceptions, enforce the standard with tooling, and keep the team aligned on one clear naming policy.
If your team is refining a naming policy now, use this article as the baseline for your next javascript style guide. The most maintainable code is not the code with the most rules; it is the code where everyone follows the same ones.
