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

后端 未结 6 1094
暗喜
暗喜 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:05

    On Chrome 52 :

    [1,].length --> 1
    [1,2,].length --> 2
    [].length --> 0 
    [,].length --> 1    <<<<=== OUHHHHH !!!!
    

    I just don't like trailing commas. People usually use them in Open Source projects for avoiding to erase the line written by another commiter. See the same question in Python : https://stackoverflow.com/a/11597911/968988

提交回复
热议问题