JavaScript article thumbnail image.

How do you use the concat() method to combine two strings in JavaScript?

The concat() method concatenates a string argument to the calling string and returns a new string.

In the examples below, we will take two strings and combine them using the concat() method.

Here's the full code:

const str1 = "Taco"
const str2 = "Bell"

const newString = str1.concat(str2)
// newString = "TacoBell"

And we can add a space between the two words with either of the two methods below:

const newString = str1.concat(" ").concat(str2)
// newString = "Taco Bell"

const newString = str1.concat(" ", str2)
// newString = "Taco Bell"

As you may have noticed, the concat() method takes a variable number of arguments. And each argument will be concatenated to the original string.

For more information on the concat() method, check out the Mozilla Web Docs on the subject.

Thanks for reading and happy coding!

About the author

Hi, I'm Nick Major. I'm a software developer from Wisconsin, United States.

I create free and premium courses, have published hundreds of informational coding articles, and am currently a Frontend Software Engineer at RoundingWell.

You can read more about me here.

Picture of Nick Major.