JS: What's the difference between =+ and +=
This question already has an answer here:
=+
will cast implicitly x
to a number and assign sumX
the value
+=
will add x
to sumX
without an attempt at casting
sumY += y;
adds y
to sumY
. sumY =+ y;
is equivalent to sumY = (+y);
. For numbers, the unary plus operator is a no-op, so the entire expression simply assigns y
to sumY
. 上一篇: `1L`和`1`有什么区别?
下一篇: JS:= +和+ =有什么区别