It will be rated as below,
1: +[] == 0 → +"" == 0
The + operator has the highest priority than == , so it will be evaluated first. Thus, when converting an array to a number, the ToPrimitive() function will be called by passing it as an argument. Since [] is an object , it will return the string ""
2: +"" == 0 → 0 == 0
An empty string will be converted to 0 . And a non-empty string will be converted to NaN , as we all know.
3: 0 == 0 → true
And finally, according to the abstract equality comparison algorithm , when both operands of the same type are compared, no further evaluation will occur, it will directly check for its equality and return the result.
And in your second case 1+[+[]] score will look like,
1: 1+[+[]] - ( +[] will be first converted to a primitive, since [] is an object)
2: 1+[+""] ( toPrimitive([]) will be "" )
3: 1+[0] ( 0 will be displayed when converting an empty string to a number)
4: 1+"0" ( toPrimitive([0]) will be "0" )
5: "10"
source share