JavaScript naming conventions: do’s and don’ts

JavaScript naming conventions: do’s and don’ts

A brief guide on naming conventions in JavaScript.

A brief guide on naming conventions in JavaScript.

I find it amazing how many different meanings we can get from less than 30 characters. I’m talking about the alphabet with some well-placed punctuation, of course. From a love store to a computer program, writing has allowed us to create extraordinarily different worlds. And language, in general, provides a framework in which we can hang a stream of ideas.

Most programming languages seem to have very strict standards — certain terms have to be used in certain places. But one area where there is an enormous amount of freedom is how we name those terms.

Take this simple program which creates a sentence from an array of words, adds a punctuation mark, and logs it to the console:

Nothing too special, right? But what you may not have considered is how many terms you were responsible to name.

There are 23 words (not including hard-coded values) in the above program. We controlled the names of 14 of those words. That is more than 60% of what was typed, was our responsibility to name!

You are responsible for the majority of the names in your program

Whether you are building an enterprise application or a simple Hello, World, you want your program to read like a Times Bestseller, not a Mad Libs workbook.

This is not a manifesto on how to structure an entire JavaScript application, but rather a chapter on how to choose names for those things in which you have the freedom to do so. I’ve included the various references at the bottom if you want to learn more. One last thing, the key takeaway of all of our conventions and standards is this:

Most of these conventions are not for you today, but instead, for you and the people reading your code tomorrow.

References and continued learning

  1. “Clean Code” by Robert C. MartinA great read for all languages. It goes beyond naming conventions and proposes the entire structure of your program. The examples are in Java, but the principals apply to JavaScript.
  2. “Clean Code JavaScript” by Ryan McdermottThe above book, but remade for JavaScript. It is available online and is free.
  3. Airbnb JavaScript Style GuidePossibly the most comprehensive style guide for JavaScript. It contains not only the what, but also the why. (If you’re on a small device, you may need to click on “view all readme” to see the entire document).
  4. W3 JavaScript Style Guide — A s_hort and concise guide._
  5. Google’s ES6 Style GuideGoogle’s style guide for JavaScript.

Learn More

Full Stack Developers: Everything You Need to Know

ES5 to ESNext — here’s every feature added to JavaScript since 2015

5 Javascript (ES6+) features that you should be using in 2019

12 Concepts That Will Level Up Your JavaScript Skills

Vuejs 2 Authentication Tutorial

Authenticate a Node ES6 API with JSON Web Tokens

Build a CMS with Laravel and Vue

The Complete JavaScript Course 2019: Build Real Projects!

JavaScript Bootcamp - Build Real World Applications

JavaScript: Understanding the Weird Parts

Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)

The Full JavaScript & ES6 Tutorial - (including ES7 & React)

Thanks for reading!

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.

How to Retrieve full Profile of LinkedIn User using Javascript

I am trying to retrieve the full profile (especially job history and educational qualifications) of a linkedin user via the Javascript (Fetch LinkedIn Data Using JavaScript)

Java vs. JavaScript: Know The Difference

Java vs. JavaScript: Know the Difference, Java vs. JavaScript: What's the Difference? Java vs. JavaScript: Major Similarities and Differences. pros and cons of JavaScript and Java.