Are trailing commas in arrays and objects part of the spec?

后端 未结 6 1201
暗喜
暗喜 2020-11-22 10:26

Are trailing commas standard in JavaScript, or do most browsers like Chrome and Firefox just tolerate them?

I thought they were standard, but IE8 puked after encount

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 11:19

    You can find the specification for javascript (aka ECMA Script) here. You can find the relevant definition for arrays on page 63 and as Felix noted, the object definition a couple of pages later on page 65.

    While this specification says it is fine to have a trailing , I don't know if that would be true looking back a few versions. As you've noted IE8- will crap itself if you leave a trailing comma but Chrome and FF handle it fine.

提交回复
热议问题