Why does ++[[]][+[]]+[+[]] return the string “10”?

后端 未结 9 2170
傲寒
傲寒 2020-11-22 06:50

This is valid and returns the string \"10\" in JavaScript (more examples here):

9条回答
  •  無奈伤痛
    2020-11-22 07:36

    +[] evaluates to 0 [...] then summing (+ operation) it with anything converts array content to its string representation consisting of elements joined with comma.

    Anything other like taking index of array (have grater priority than + operation) is ordinal and is nothing interesting.

提交回复
热议问题