Difference between += and =+ in javascript

javascript

Solution

Awkward formatting:

a =+ b;

is equivalent to:

a = +b;

And `+b` is just a fancy way of casting `b` to number, like here:

var str = "123";
var num = +str;

You probably wanted:

a += b;

being equivalent to:

a = a + b;

Problem

I want to know why after running the third line of code the result of `a` is 5? ``` a = 10; b = 5; a =+ b; ```

Original source

Related problems