Reputation: 7739
I would think you might get 0
, maybe because the strings are turned to 1's
and the -
operator causes a subtraction operation to take place?
"1" - - "1";
Thanks in advance!
Upvotes: 4
Views: 111
Reputation: 8663
The -
casts the string to a number and also acts as a minus sign.
1 - (-1)
= 1 + 1
= 2
Upvotes: 2
Reputation: 138
1 - (-1) = 2. I dont see the issue? JavaScript will parse those as integers because of the minus sign, expecting math. It also happens if you multiply a numerical string by 1, aka the poor man's parseInt().
Upvotes: 1