Before we say the rules, let's take a look at the results of the following code:
1Console.log (1 + "2" + "2");//1222 3Console.log (1 + + "2" + "2");// +4 5Console.log (1 +-"1" + "2");// Geneva6 7Console.log (+ "1" + "1" + "2");// the8 9Console.log ("A"-"B" + "2");//NaN2Ten OneConsole.log ("A"-"B" + 2);//NaN
Rules:
1. Multiple numeric and numeric string blending operations are related to the position of the operand.
Such as:
Console.log (2 + 1 + ' 3 '); //' 33 '
Console.log (' 3 ' + 2 + 1); ' 321 '
2. A numeric string is converted to a number when it is preceded by a positive sign (+/-) in the number
Such as:
Console.log (typeof ' 3 '); String
Console.log (typeof + ' 3 '); Number
3. You can add a number to a string before the number
Such as:
Console.log (typeof 3); Number
Console.log (typeof (' +3)); String
4. If the result of the operation cannot be converted to a number, it will return NaN
Such as:
Console.log (' a ' * ' SD '); NaN
Console.log (' A '-' B '); NaN
Multiple numeric and numeric string blending rules