Table of Contents
- Using the concat() method
- Using the + operator
- Using the array join() method
- Using the template literal
- Other Related Concepts
Using the concat() methodAs the name suggests, this method joins or merges two strings. This method does not alter the input/given strings, instead, it returns a new string that has both the input strings concatenated.
Here, the parameters string1, string2, ..., stringN are the strings that to be concatenated.
One can also concat strings using the + operator using the shorthand += operator
Using the array join() methodThe join() method is used to concatenate all the elements of an array into a string. The elements will be separated by a specified separator. When no separator is specified, the default separator is the comma (,). The array join() method does not alter the original array
Here the Separator is an optional parameter
Using the template literalTemplate literals are string literals allowing embedded expressions. Using these template literals one can also use multi-line strings and string interpolation features with them.