How to combine 2 JavaScript variables into a string?

Sometimes, we want to combine 2 JavaScript variables into a string.

In this article, we’ll look at how to combine 2 JavaScript variables into a string.

How to combine 2 JavaScript variables into a string?

To combine 2 JavaScript variables into a string, we can use the + operator concatenate them.

For instance, we write:

const a = 1;
const b = "abc";
const c = b + a;
console.log(c)

to concatenate b and a together with + and assign the returned result to c.

Therefore, c is 'abc1'.

Conclusion

To combine 2 JavaScript variables into a string, we can use the + operator concatenate them.