+ 1

Why?

Why JS don't add numbers, he add chars?(sometimes)

25th Dec 2017, 7:25 PM
Crinax
Crinax - avatar
2 ответов
+ 13
""+1+2 == 12 because priority is like this : ((""+1)+2) == "1"+2 == "12" as you can see js does auto typecasting with priority from left to right 1+2 == 2 (no strings in operations) perhaps the values you're trying to add are not all pure numbers.
25th Dec 2017, 7:31 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
25th Dec 2017, 9:47 PM
Scooby
Scooby - avatar