+ 2
Why does this print "76"?
From a JS Challenge, the following code var x = 7 + "2"; var y = 4 - "8"; alert(x-y); alerted "76". Can someone explain why?
2 odpowiedzi
+ 7
var x =7 +"2" wihich gives 72
var y = 4 - "8" which gives -4
in the first line the 7 and 2 are concatenated
but in secon line the "-" sign doesn't concatenate the two values so it converts "8" to int..
and yields -4
+ 3
thanks! that's a nice way to show when they concatenate or not!