First, the interpreter parses true + true
.
These operands are not strings, so only addition is performed, in mathematical operations true
and false
automatically become 1 and 0.
Therefore, if you add true + true, you get 2.
The +
operator is used for both addition and concatenation.
If one of the operands is a string, the interpreter will always choose concatenation rather than addition.
typeof NaN
returns string 'number'
. Length of this string is 6.<br>
As a result, it turns out that on the left is the string '20', and on the right is the number 6, and between them is the -
operator.
Minus is only a mathematical operator, so the interpreter sees that the operand on the left is not number, and automatically converts it to number.