UPPERCASE with _ is pretty much the standard for hard-coded Constants in JavaScript

I was exporting a string constant to a constants file in React project and wondered if I had to create a variable with UPPERCASE AND _, because it is not so friendly in terms of typing, but after searching through web for established best practices, I am also joining the party, so my constant variables will be like this

const WITHDRAW = 'Withdraw' // instead of const withdraw = 'Withdraw';

const NEW_COUPON = ‘HAPPY' // instead of const newCoupon = ‘Happy'

Following are just the list of resources which convinced me to follow the above approach

  1. JavasScript.info says:

…capital-named constants are only used as aliases for “hard-coded” values.

2. As per Google style guide

Use NAMES_LIKE_THIS for constant values.

3. Some illustration from Airbnb style guide

// bad
const PRIVATE_VARIABLE = 'should not be unnecessarily uppercased within a file';

// bad
export const THING_TO_BE_CHANGED = 'should obviously not be uppercased';

// bad
export let REASSIGNABLE_VARIABLE = 'do not use let with uppercase variables';

// ---

// allowed but does not supply semantic value
export const apiKey = 'SOMEKEY';

// better in most cases
export const API_KEY = 'SOMEKEY';

// ---

// bad - unnecessarily uppercases key while adding no semantic value
export const MAPPING = {
KEY: 'value'
};

// good
export const MAPPING = {
key: 'value'
};

4. Constants can be declared with uppercase or lowercase, but a common convention is to use all — uppercase letters. — from MDN

5. Yes, UPPER_SNAKE_CASE for constants is a convention which transcends language. -Reddit Post

Let me know your thoughts!

I love learning