alert(5+'5') \\ 55
alert(5-'5') \\ 0
What is going here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In short terms, nothing wrong here!
The
+operator is “overloaded” for strings as well and works as a concatenation operator. If you apply+to a number and a string it acts like a string concat operator.The
-operator is not “overloaded” for strings. If you apply-to a number and a string it will try to convert the string to number and then do the subtraction, if possible.