How do I concatenate strings in JavaScript?

To concatenate strings in JavaScript, you can use the "+" operator or the string.concat(str1, str2, ...) method. The "+" operator is used to create a new string or modify (mutations) an existing line using the "+=" operator. The concat() method takes one or more strings as parameters and creates a new string. The method does not modify the provided strings but creates and returns a new string as the result of concatenating the passed strings. You can also use the array.join(separator) method for string concatenation, which joins all the elements of an array and returns a new string. The join() method takes a delimiter as a parameter (the default is a comma ","). In this JavaScript String Concatenate example, we use the "+" operator. More examples of string concatenation are given below. Click Execute to run the JavaScript String Concatenation Example online and see the result.
Loading...