JavaScript =+ operator

+= (addition operation)

+=is jsthe addition operation of , the expression A += Brepresents: A = A + B.

as follows:
insert image description here

=+ (special assignment)

JavaScriptIn =+is a special assignment, the expression A =+ Bmeans: Bconvert 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:
insert image description here

Guess you like

Origin blog.csdn.net/HH18700418030/article/details/130703812