Hassan Ali Hassan Ali - 1 year ago 80
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;

And Its Html:

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

Mir Mir
Answer Source

They have become strings. Convert to number

var var3 = Number(var1) + Number(var2); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download