Naming Conventions Across Languages (part one JS)

Naming Conventions Across Languages (part one JS)

Writing clean code is more than just making the code work — it’s about making it readable, understandable, and maintainable. One of the key factors in writing clean code is naming conventions. Using consistent and meaningful names for variables, functions, and modules can help make your code more understandable not just for yourself, but for future developers who might work with your code.

In this article, we’ll explore how to write descriptive names for variables, functions, and modules across four popular languages: JavaScript, TypeScript, Solidity, and Python. We’ll also discuss common naming conventions for each language, highlighting both similarities and differences.

Why Naming Conventions Matter

Imagine you come across the following code:

function f(x, y) {
return x * y;
}

Versus:

function calculateTotalPrice(quantity, pricePerItem) {
return quantity * pricePerItem;
}

The second example is self-explanatory and immediately tells you what the function does. This is what clean code strives for — clarity and intent. When you read it, there is no guesswork about what the code does or how it works.

Naming conventions help achieve this clarity. Let’s explore how these conventions apply in different languages.

Naming Conventions in JavaScript

JavaScript is a dynamically typed language that is often used for both front-end and back-end development. Here are some best practices for naming conventions in JavaScript:

Variables

camelCase is the standard for variable names:

let totalAmount = 100;
let userName = "Jordan";

Boolean variables often start with is, has, or should:

let isLoggedIn = true;
let hasPermissions = false;

Functions

Function names should be action-oriented and follow camelCase:

function calculatePrice() {}
function fetchData() {}

If a function returns a boolean, start with is, can, or has:

function isAuthenticated() {}

Modules

Modules or files should be lowercase with dashes if needed:

user-controller.js
data-fetcher.js