+ 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.

26th Jun 2017, 2:52 PM
jovanad92
jovanad92 - avatar
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.
26th Jun 2017, 2:56 PM
Calviղ
Calviղ - avatar
+ 3
Oh! I see it now. Thank you, Calvin :D
26th Jun 2017, 3:12 PM
jovanad92
jovanad92 - avatar
0
helped me too thanks for that
29th Jun 2017, 3:47 PM
aradhya
aradhya - avatar
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?
20th Aug 2020, 5:28 PM
Okali Emmanuella
Okali Emmanuella - avatar