given the following block of code
var sumX = 0,
sumY = 0,
x = 1,
y = 2;
sumX =+ x;
sumY += y;
What is the difference between the two assignment operators?
given the following block of code
var sumX = 0,
sumY = 0,
x = 1,
y = 2;
sumX =+ x;
sumY += y;
What is the difference between the two assignment operators?
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
.=+
will cast implicitly x
to a number and assign sumX
the value
+=
will add x
to sumX
without an attempt at casting