+ 5
Adding number and string
Sometimes numbers are adding like numbers, sometimes like strings. Is there a rule about it? https://code.sololearn.com/W9cK75LnEyOS/?ref=app
5 Respostas
+ 8
But in first example are 2numbers 0 & 7; and they are adding like strings
+ 5
1+1+"j" //type string output:2j because the number before string
"j"+1+1//type string output:11j because the string before number
+ 5
So why 1+1+ "j" is not 1+"1j", = 11j; it makes no sense
+ 4
Sławek J. The type becomes a string so in the example 7+""+7 is string and 0 + string = 077
+ 4
See brother:
a=0;
a+=1+""; // first it starts in 1+"" And 1+"" = 1 but in string like 1+1*2=3 because multiplication before the addition so 0 + 1 in string == 01 and in yours ==077