JavaScript String concat()

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


let emptyString = "";

// joint arguments string let joinedString = emptyString.concat("JavaScript", " is", " fun.");
console.log(joinedString); // Output: JavaScript is fun.

concat() Syntax

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.

concat() Return Value

  • 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!

Also Read:

Did you find this article helpful?