What is the standard convention naming for property inside object?
camelCase
or
snake_case?
Here's an example:
let objPerson = {
first_name: 'first',
last_name: 'last'
};
or
let objPerson = {
firstName: 'first',
lastName: 'last'
};
Any remendation for a site to learn naming standardization of objects? I tried to google it but couldn't find an answer. Also the name of the object should be objPerson
or ObjPerson
because it is an object
What is the standard convention naming for property inside object?
camelCase
or
snake_case?
Here's an example:
let objPerson = {
first_name: 'first',
last_name: 'last'
};
or
let objPerson = {
firstName: 'first',
lastName: 'last'
};
Any remendation for a site to learn naming standardization of objects? I tried to google it but couldn't find an answer. Also the name of the object should be objPerson
or ObjPerson
because it is an object
- 1 You can choose - only real convention for name format is to start constructor and classes with a capital (and even then it's your own choice). – Jack Bashford Commented Mar 29, 2019 at 8:52
- i would go for the second option, because it is shorter to write and underscores makes code nervous. – Nina Scholz Commented Mar 29, 2019 at 8:54
- PascalCase for classes and camelCase for the rest are conventional in JS. There's no official standard. – Estus Flask Commented Mar 29, 2019 at 9:08
- There is no rule, however there is a rule that string literals should be terminated. – trincot Commented Mar 29, 2019 at 9:12
- As other have said, it's a matter of personal preference (I'm on board with @estus). Whatever you decide on, it might be a good idea to set up eslint and set a rule with your choice, so you are consistent. – Atheist Commented Mar 29, 2019 at 9:31
1 Answer
Reset to default 4It's not really a standard, but i've seen more snake case in my days. You can choose whatever you like, it's just important that you use the same type during a project.