The concat() Method in JavaScript Strings
In JavaScript, the concat()
method is used to concatenate strings. It combines the current string with the string passed as a parameter.
Usage Example
Here’s an example to demonstrate the usage of the concat()
method:
1 | console.log('Flavio'.concat(' ', 'Copes')); // Output: Flavio Copes |
In this example, the concat()
method is used to concatenate the string ‘Flavio’ with the string ‘Copes’. The result is the combined string ‘Flavio Copes’.
Concatenating Multiple Strings
The concat()
method can also concatenate multiple strings together. You can specify a variable number of arguments to the concat()
method, and all those arguments will be concatenated to the original string.
1 | console.log('Flavio'.concat(' ', 'Copes', ' is a', ' developer')); // Output: Flavio Copes is a developer |
In this case, the concat()
method combines the string ‘Flavio’, ‘Copes’, ‘ is a’, and ‘ developer’ into a single string ‘Flavio Copes is a developer’.
That’s all there is to know about the concat()
method in JavaScript strings. It’s a handy tool for combining strings together.
tags: [“JavaScript”, “strings”, “concat()”, “concatenation”]