How to concatenate two numbers in javascript?
Use "" + 5 + 6
to force it to strings. This works with numerical variables too:
var a = 5;
var b = 6;
console.log("" + a + b);
just use:
5 + "" + 6
You can now make use of ES6 template literals.
const numbersAsString = `${5}${6}`;
console.log(numbersAsString); // Outputs 56
Or, if you have variables:
const someNumber = 5;
const someOtherNumber = 6;
const numbersAsString = `${someNumber}${someOtherNumber}`;
console.log(numbersAsString); // Outputs 56
Personally I find the new syntax much clearer, albeit slightly more verbose.
var value = "" + 5 + 6;
alert(value);