JavaScript String concat() method

The concat() method in JavaScript is used to concatenate two or more strings together. This method takes one or more string arguments, and returns a new string that is the result of concatenating all the arguments together.

Here is an example of how the concat() method works:

const string1 = 'Hello';
const string2 = ', world';

const result = string1.concat(string2);

// the result will be: 'Hello, world'

In the code example above, we first declare two strings called string1 and string2 that contain the text Hello and , world, respectively. We then use the concat() method to concatenate the string1 and string2 strings together. The concat() method takes one or more string arguments, and returns a new string that is the result of concatenating all the arguments together. In this case, we pass in the string2 string as the argument to the concat() method.

As a result of calling the concat() method, the result variable will be set to 'Hello, world', which is the result of concatenating the string1 and string2 strings together.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: