0

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

12th Jun 2016, 2:34 AM
Avdhoot yadav
Avdhoot yadav - avatar
3 odpowiedzi
+ 7
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.
12th Jun 2016, 9:49 AM
ZinC
ZinC - avatar
+ 1
JavaScript concatenates string and add numbers.
17th Jun 2016, 2:35 PM
Victor Ogudu
Victor Ogudu - avatar
0
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.
5th Sep 2016, 3:30 AM
Aniekan
Aniekan - avatar