concat method

The concat method combines given strings. The number of strings to concatenate is not limited. In fact, the action of this method is similar to the operation '+' for string concatenation.

Syntax

javascriptstring.concat(another string, and another string, and another...);

Example

Let's use the concat method to merge three strings into one:

javascriptlet str1 = 'a';
let str2 = 'b';
let str3 = 'c';
let res = str1.concat(str2, str3);

console.log(res);

The code execution result:

javascript'abc'

Example

You can apply the method to an empty string. In this case, all the strings to be concatenated will be passed as the method parameters:

javascriptlet str1 = 'a';
let str2 = 'b';
let str3 = 'c';
let res = ''.concat(str1, str2, str3);

console.log(res);

The code execution result:

javascript'abc'

See also

  • the concat method
    that concatenates arrays into one