the + operator some times it does nt add the numbers instead it concat those 2 numbers?

for example var a =2; var b=5; var result= a+b; document.write(result); o/p : 25

6/12/2016 2:34:56 AM

Avdhoot yadav

3 Answers

New Answer


It concatenates strings and adds numbers. var a="2"; var b="3"; document.write(a+b); Returns 23. var a=2; var b=3; document.write(a+b); Returns 5.


JavaScript concatenates string and add numbers.


When you want to add, avoid single or double quotes when dealing with numbers else JavaScript will take them as strings. when that happens, you get concatenation instead of addition.