Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
JavaScript String concat()
In this tutorial, we will learn about the JavaScript String concat() method with the help of examples.
The concat() method concatenates given arguments to the given string.
Example
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!
Output
[object Object] null true 45 Hello, World!
Also Read:
Did you find this article helpful?