I have a variable
var number = 1;
I'm then trying to add a 2 onto a number but not add them together like this.
1 + 2 = 2
but instead I want, to join 2 onto the number so i would get
12
I have a variable
var number = 1;
I'm then trying to add a 2 onto a number but not add them together like this.
1 + 2 = 2
but instead I want, to join 2 onto the number so i would get
12
One way is to add an empty string between the numbers like so:
var number = 1;
var result = number + "" + 2;
alert(result);
Another way it to cast the number to a string using toString()
var number = 1;
var result = number.toString() + 2;
alert(result);