Why does javascript accept commas in if statements?

后端 未结 5 1027
北荒
北荒 2020-11-29 23:47

I stumbled across some javascript syntax that seemed like it should produce a parse error of some kind but doesn\'t:

if (true, true) {console.log(\'splendid         


        
5条回答
  •  猫巷女王i
    2020-11-30 00:24

    The comma operator chains multiple expressions together, and the result of the operation is the value of the last operand. The only real use for it is when you need multiple side effects to occur, such as assignment or function calls.

提交回复
热议问题