+ 1

Can somebody explain how this code gives the answer 76

var x = 7 + "2"; var y = 4 - "8"; alert(x-y);

4th Dec 2021, 12:08 PM
Steve Nova
Steve Nova - avatar
3 Réponses
+ 7
In, var x = 7+"2" x = 72 In, var y = 4-"8" y = -4 So, x-y = 72-(-4) = 76
4th Dec 2021, 12:12 PM
Ananya | Inactive |
Ananya | Inactive | - avatar
+ 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
4th Dec 2021, 3:01 PM
A͢J
A͢J - avatar
+ 2
nicely explained awesome thanks 👍
4th Dec 2021, 12:23 PM
Steve Nova
Steve Nova - avatar