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