DEV Community

Discussion on: Demystifying "const" variables in JavaScript

adam_cyclones profile image
Adam Crockett

Do you like constant case?

johncip profile image
jmc • Edited on

Not OP, but I mentally distinguish between "values," which use const but tend to be local / temporary, and "constants," which also use const but tend to be in outer scope. I use screaming snake case only for the latter, if at all.

IMO when most of your values are immutable, which is a good place to be, the constants stop being special. Instead, the the things that can change over time are special, as they should be, since they require more effort to reason about.

sunnysingh profile image
Sunny Singh Author • Edited on

I do, for real constants that are static values. Consider this example:

const BASE_URL = '';

const url = `${BASE_URL}/hello`;

Since url isn't a true constant (it uses another variable to determine its value), I keep it lowercase.

Also, I only use constant case at the top level scope, or when I'm importing constants from another file.