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

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

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

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 07:39

    ++[[]][+[]] => 1 // [+[]] = [0], ++0 = 1
    [+[]] => [0]
    

    Then we have a string concatenation

    1+[0].toString() = 10
    

提交回复
热议问题