JavaScript Code

JavaScript String concat()


String concat()

str1.concat(str2)
str1.concat(str2, str3)
str1.concat(str2, str3, str4, .., strN)
  • str1, str2, str3,.. strN are strings

concat() method takes one or more strings as arguments, concatenates them with the calling string, and returns the resulting string. original string str is not modified.

Examples

1. concatenate two strings

let str1 = 'apple';
let str2 = 'banana';
let output = str1.concat(str2);
console.log(output);

2. concatenate three strings

let str1 = 'apple';
let str2 = 'banana';
let str3 = 'cherry';
let output = str1.concat(str2, str3);
console.log(output);

Copyright @2022