![]() |
VOOZH | about |
The concat() method in JavaScript join or concatenate two or more strings together. It does not change the existing strings and returns a new string. This method efficiently combines multiple strings into one, ensuring the original strings remain unchanged.
str1.concat(str2, str3, str4,......, strN)Note: If the parameters are not of String type, then first it converted to string before concatenating the strings.
Returns a new string that is the combination of all the different strings passed to it as the argument.
The string "str" is initialized with the value "Welcome". Then concat() method is used on str to combine it with "Geeks".
Welcome Geeks
The concatenates strings str1, str2, and str3 together. The result1 combines them without spaces, while result2 concatenates them with spaces.
Result without spaces: GeeksForGeeks Result with spaces: Geeks For Geeks
You can use the concat() method with empty strings to control the formatting or add spaces dynamically