4

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!

1
  • But isn't 1-(-1) = 1+1 = 2 Commented May 28, 2015 at 15:03

3 Answers 3

11

It's how math works

1 - (-1) = 1 + 1
Sign up to request clarification or add additional context in comments.

Comments

2

The - casts the string to a number and also acts as a minus sign.

1 - (-1) = 1 + 1 = 2

Comments

1

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().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.