最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the standard naming convention of properties in a object, camelCase or snake_case? - Stack Overflow

programmeradmin1浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论