Everybody knows the basic concatenation of two strings in JavaScript:
> "Hello " + "World!"
'Hello World!'
But what happens if we use + + instead of +? I just encountered the following weird behavior:
> "Hello " + + "World!"
'Hello NaN'
> "Hello " + + ""
'Hello 0'
From the examples above, I can see that the second string is converted into number. So, passing an object having valueOf property as function, the value returned by that function will be converted.
> "Hello " + + ({valueOf: function () {return 1; }})
'Hello 1'
As expected, it shows "Hello 1".
Why is the second string converted in Number? Why not throwing a syntax error or so?
+ +(+ <space> +).