How to concatenate two strings in JavaScript

Learn how to combine strings using JavaScript

JavaScript, like any other good language, has the ability to concatenate two (or more) strings.

how is it?

We can use+operator.

If you have a stringnameAnd a stringsurname, You can also assign thesefullnameVariables like this:

const fullname = name + surname

If you don’t want to instantiate a new variable, you can use+=Operator to add the second string to the first:

name += surname

Alternatively, you can also useconcat()The method of the String object, this method returns a new string that connects the string you call this method with the method's parameters:

const fullname = name.concat(surname)

I usually recommend the easiest route (which also happens to be the faster route) to use+(or+=) operator.

Download mine for freeJavaScript beginner's manual

More js tutorials: