Why does alert(“1” - - “1”); produce 2 in javascript?

When I execute the following javascript statement:

alert("1" - - "1");

I get the result 2.

Why is this?



Since you can't subtract strings, the - operator converts them to numbers. If you subtract negative one from positive one you get two.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.