Calculate the value of the following expression:
[''] == false
First, the two operands are object type and boolean type. According to Figure 1, it is necessary to convert the Boolean type to a numeric type, and the result of converting false to a numeric is 0, so the expression becomes:
[''] == 0
The two operands become object type and numeric type. According to Figure 1, the object type needs to be converted to the original type:
First, call [].valueOf(). Since the valueOf() method of the array returns itself, the result is not the original type. Continue to call [].toString().
For arrays, the algorithm of the toString() method is to convert each element into a string type, and then concatenate it in sequence with commas ',', so the final result is an empty string ', which is a value of the original type.
At this point, the expression becomes:
'' == 0
The two operands become string types and numeric types. According to Figure 1, it is necessary to convert the string type to a number type. As mentioned earlier, the empty string becomes a number of 0. So the expression becomes:
0 == 0
So far, the types of the two operands are finally the same, and the result is obviously true.