+ 1
Can somebody explain how this code gives the answer 76
var x = 7 + "2"; var y = 4 - "8"; alert(x-y);
3 Answers
+ 7
In, var x = 7+"2"
x = 72
In, var y = 4-"8"
y = -4
So, x-y = 72-(-4)
= 76
+ 3
Steve Nawa đłđŚ
plus (+) is used to concat string in JavaScript.
Here 7 is a number but 2 is a string so it would be concat so
x = 72
But string can be subtract, multiply and divide so
y = -4
Now x - y = 72 - (-4) = 76
+ 2
nicely explained awesome thanks đ