Home > Software design >  Should I write the name of states, cities in capitals for JavaScript code while it's naming con
Should I write the name of states, cities in capitals for JavaScript code while it's naming con

Time:04-21

I'm a junior JS developer, and I'm not sure what's considered best practice for naming the variables that might be connected to the front-end interface. For example, I'm trying to provide a list of the states and their cities; I was wondering if I should abide by the JS naming conventions for writing Object property names or write them in CAPITALS. And also, should I put space between the multi-part names or better not?

sum up:

  • naming object properties
  • naming array element as a value of object property of an object
  • naming the parent object itself
  • in Capitals ?? with spaces ??

For example:

let states = {
    Alabama: ["Alexander City", "Andalusia", "Anniston", "Athens"],
    Alaska: ["Anchorage", "Cordova"],
    Arizona: ["Lake Havasu City", "Window Rock"],
    Arkansas: ["Arkadelphia", "Benton"],
    California: ["Costa Mesa", "Mountain View"],
};

CodePudding user response:

camelCasing is generally used as a best practice for naming variables and sometimes object keys; however, object keys can be snake_cased or have the First letter be capital and still be following best practices.

The array values are fine and should stay as is.

  • Related