How to concatenate two numbers in javascript?

Solution 1:

Use "" + 5 + 6 to force it to strings. This works with numerical variables too:

var a = 5;
var b = 6;
console.log("" + a + b);

Solution 2:

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.

Solution 3:

var value = "" + 5 + 6;
alert(value);