Why +[] or +"" equal to 0 in javascript

This question already has an answer here:

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

  • Because empty string ("") is false in javascript (As Javascript is a dialect of ECMAScript, and ECMAScript language specification clearly defines this behavior) and + unary operator converts false to 0 .

    Reference : http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

    链接地址: http://www.djcxy.com/p/48056.html

    上一篇: JavaScript的内建字符串是什么?

    下一篇: 在javascript中,为什么+ []或+“”等于0