Why does alert("1" - - "1")
return 2?
I'm not entirely sure what is going on here to create the result as 2?
I came across the problem here: http://davidshariff.com/js-quiz
Why does alert("1" - - "1")
return 2?
I'm not entirely sure what is going on here to create the result as 2?
I came across the problem here: http://davidshariff.com/js-quiz
it's like writing 1 - (-1) which is 1 + 1 = 2
the problem in js is that if you use + between 2 string it means concating them thus resulting 11
EDIT: thanks to iamnotmaynard comment i was able to find this post
Why does JavaScript handle the plus and minus operators between strings and numbers differently?