JavaScript String concat()

The JavaScript String concat() method concatenates given arguments to the given string.

The syntax of the concat() method is:

str.concat(str1, ..., strN)

Here, str is a string.

concat() Parameters

The concat() method takes in an arbitrary number of strings to concatenate to str.

Return value from concat()

  • Returns a new string containing the combined text of the strings provided.

Note: The assignment operators like + and += are strongly recommended over the concat() method.

Example: Using concat() method

console.log("".concat({})); // [object Object]
console.log("".concat(null)); // null
console.log("".concat(true)); // true
console.log("".concat(4, 5)); // 45

let str1 = "Hello";
let str2 = "World";

// concatenating two strings
let newStr = str1.concat(", ", str2, "!");
console.log(newStr); // Hello, World!


[object Object]
Hello, World!

Recommended Reading: JavaScript Array concat()

Did you find this article helpful?