DEV Community

Aditya Singh
Aditya Singh

Posted on

2

JavaScript Naming Conventions: Unlocking the Secrets to Clear and Concise Code

💡 The naming convention play a crucial role in JavaScript development. They serve as a roadmap, guiding developers towards writing clean, maintainable, and readable code. By following these guidelines, you will not only improve your own development experience but also make your code more accessible to other developers.

Variables

JavaScript variables names are case-sensitive, lowercase and uppercase letters are distinct. Recommended way to declare, is with camel case variable names.

let newName = 'John';
Enter fullscreen mode Exit fullscreen mode

Boolean

Boolean variables plays a crucial role in JavaScript programming by representing true or false conditions. When naming Boolean variables, we should use is or has as prefixes.

let hasEmail = true;
Enter fullscreen mode Exit fullscreen mode

Functions

Similar to variables, the camel case approach is recommended way to declare function names. In addition to that you should use nouns and verbs as prefix.
Example: If we declare a function to retrieve a name, the function name should be getName.

function getDetails(name, email){
    return '${name} ${email}';
}
Enter fullscreen mode Exit fullscreen mode

Constants

The constants should be written in uppercase because they are nonchanging variables.

const PIE = 3.14
Enter fullscreen mode Exit fullscreen mode

Classes

The classes should be written in pascal case. Here we have to use descriptive titles that explain the class’s capabilities.

class NewDetails{
    constructor(name, email){
        this.name= name;
        this.email = email; 
    }
}
var detail = newDetails('John', 'john@gmail.com')
Enter fullscreen mode Exit fullscreen mode

Component

JavaScript components are widely used in frontend frameworks like React. Similar to classes, the pascal case approach is recommended way to declare component names.

function NewDetails(detail){
    return(
        <div>
            <h1>{detail.name}</h1>
        </div>
    );
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

By applying these practices, you'll enhance collaboration, ease debugging, and ensure a smoother development experience. Embrace the power of effective naming conventions and unlock the full potential of your JavaScript codebase.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay