解决方法
在第一种情况下,您使用
Unary plus
+
The unary plus operator precedes its operand and evaluates to its operand but attempts to convertit into a number,if it isn’t already. Although unary negation (-) also can convert non-numbers,unary plus is the fastest and preferred way of converting something into a number,because it does not perform any other operations on the number. It can convert string representations of integers and floats,as well as the non-string values
true
,false
,andnull
. Integers in both decimal and hexadecimal (“0x”-prefixed) formats are supported. Negative numbers are supported (though not for hex). If it cannot parse a particular value,it will evaluate to 07001.
在第二个你只使用Addition
The addition operator produces the sum of numeric operands or string concatenation.