+ 6
JavaScript number variables
Hello, everyone. I need help understanding this operation: var a = "8"; var b = a + 3 - a; document.write(c); //output is 75 Why is 75? I thought that numbers in quotes were treated as strings when they came with a plus sign. Shouldn't it be 85? This is eating my head; I can't see the logic behind this :S Thanks in advance for your help.
5 Antworten
+ 9
b = "8" + 3 - "8"
b = "83" - "8"
b = 83 - 8
b = 75
Special condition, + also use as concatenation of string if the first var is string follow by a number.
+ 3
Oh! I see it now. Thank you, Calvin :D
0
helped me too thanks for that
0
according to calvin it is 75, some people make the mistake of writing "8"+"3" is 11 but, you join them together to be 83 then i subtraction situations, you minus it by3 which gives you 73 as an answer its easy hope you understand?