admin管理员组

文章数量:1390670

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

Share Improve this question edited Mar 29, 2019 at 9:27 iLuvLogix 6,4383 gold badges29 silver badges45 bronze badges asked Mar 29, 2019 at 8:49 testminingtestmining 951 silver badge4 bronze badges 6
  • 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
 |  Show 1 more ment

1 Answer 1

Reset to default 4

It'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.

本文标签: