1, the figure

2. Implicit conversion mainly involves three types of conversion:

1. Convert value to original value, ToPrimitive(). 2. Convert values to numbers, ToNumber(). Convert the value to a string, ToString().

3, addition – toString then toNumber+ reference type

⭐️ why should addition be treated differently? Because in JS + can also be used to concatenate strings. Keep these 3 things in mind:

When one side is String, it is recognized as String concatenation, and the other side is converted to String preferentially. When one side is of type Number and the other side is of primitive type, the primitive type is converted to Number. If one side is Number and the other side is a reference type, convert the reference type and Number to a string and concatenate the two. ⭐️ 3 points above, priority from high to low, i.e. 3+’ ABC ‘applies rule 1, and 3+true applies rule 2.

123 + '123' // 123123 (Rule 1) 123 + NULL // 123 (Rule 2) 123 + true // 124 (Rule 2) 123 + {} // 123[object object] (Rule 3Copy the code

4. Subtract, multiply, and divide —- If not number, go to number

⭐️ When we apply the mathematical operator (- * /) to various non-number types, we first convert non-number types to Number types.

1-1-1 - null // 1 NaN 2 * ['5'] // 10, ['5'] will first become '5', and then the number 5Copy the code