Sometimes, we want to concatenate two numbers in JavaScript.
In this article, we’ll look at how to concatenate two numbers in JavaScript.
How to concatenate two numbers in JavaScript?
To concatenate two numbers in JavaScript, we can use template literals.
For instance, we write
const a = 5;
const b = 6;
const numbersAsString = `${a}${b}`;
console.log(numbersAsString);
to interpolate the values a
and b
into the numersAsString
template literal.
Then numbersAsString
is '56'
.
Conclusion
To concatenate two numbers in JavaScript, we can use template literals.