Categories
JavaScript Answers

How to combine 2 JavaScript variables into a string?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *