Jithin Das

Javascript Constants and Its Naming Conventions

As the saying goes, "The only constant in life is death." Quite a statement, right? It’s a hard one to express, for sure! Thankfully, in programming, we deal with plenty of constants, but most are far less grim.

So, what exactly are constants? Simply put, constants are values that don’t change. They could represent something like your birthday or the initial load time of your favourite website.

In JavaScript, we define constants using the const keyword. For example, here’s how we’d define my birth date: const MY_BIRTHDAY = '11.05.1995'. Since my birthday is fixed and known in advance, we use ALL CAPS for naming.

But there’s another type of constant, one that’s calculated in real-time and remains unchanged afterward. Think of a program that tracks the load time for each site you visit. These values are determined on the fly, so we use camelCase when naming them.

Example: const initialLoadTime = '200ms'.

#blog