Javascript “tuple” notation: what is its point?

后端 未结 3 1542
庸人自扰
庸人自扰 2020-12-24 12:44

At wtfjs, I found that the following is legal javascript.

\",,,\" == Array((null,\'cool\',false,NaN,4)); // true

The argument (null,\

3条回答
  •  情书的邮戳
    2020-12-24 13:10

    Try this alert((null,'cool',false,NaN,4)) and then you can see.

    demo

    The reason is because the comma operator evaluates all the statements and return the last one.

    Think of this line: a = 1, b = 2, c = 3; it will run each expression so in essence it will set the variables to what you want and return the last value (in this case 3)

提交回复
热议问题