To concatenate two variables in JavaScript, use the string template:
`${var1}${var2}`
.Here's how you do it:
const variable1 = 'Hello World!';
const variable2 = 23;
const concatenated = `${variable1}${variable2}`;
console.log(concatenated); // Hello World!23
Another option is to use the +
operator, but in this case one the variables must be a string:
const variable1 = 'Hello World!';
const variable2 = 23;
const variable3 = 1;
const concatenated = variable1 + variable2;
console.log(concatenated); // Hello World!23
const summed = variable2 + variable3;
console.log(summed); // 24