Hassan Ali Hassan Ali - 3 months ago 9
Ajax Question

Concatination + in javascript with variables

I have an issue with the variables + They both result me 310. But they both have to result me 13 because var1 = 3 and var2 = 10.

var var1 = document.getElementById("start").value;
var var2 = 10;
var3 = var1 + var2;
alert(var3);


And Its Html:

<input type="text" id="start" value="3" />

Mir Mir
Answer

They have become strings. Convert to number

var var3 = Number(var1) + Number(var2);