+= (addition operation)
+=
is js
the addition operation of , the expression A += B
represents: A = A + B
.
as follows:
=+ (special assignment)
JavaScript
In =+
is a special assignment, the expression A =+ B
means: B
convert to a number and assign to A
.
=
It is an assignment, +
which means that the following number is a positive number; similarly, =-
it means that the following number is a negative number.
usefulness
It is equivalent to telling the compiler that the value type to be assigned is a number type, and do not concatenate numbers as strings.
Example:
var a=10;
var b="abcd";
var c=+a;
console.log('c:', c);//return 10
var d=-a;
console.log('d:', d);//return -10
var f="10";
var e=+b;
var g=-f;
console.log('e:', e);//NAN
console.log('g:', g);//-10
Print result: