JavaScript Join two strings | Example of concat() and operator

There are many ways to Join two strings in JavaScript, like the operator and concat() method. Mostly The concat() method is used to join two or more strings.

JavaScript Join two strings Ways

  • + operator.
  • += operator
  • concat() method

Examples of Join two strings in JS

Let’s see the one one example of each ways.

1. + operator

Let’s see you have 2 string name and last_name, then you can assign those to the fullname variable like this:

Output:

JavaScript Join two strings

2. += operator

In this way you don’t needed to instantiate a new variable, see below example how to use the += operator to add the second string to the first:

3. concat() method

This method does not change the existing strings, but returns a new string containing the text of the joined strings.

Output:

JavaScript Join two strings Example of concat

Do comment if you have any questions and suggestions on this tutorial.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.