String.prototype.concat()
concat(...strings) The concat() method merges two or more strings into a new string. It takes one or more string arguments and appends them to the original string in the order they were passed. The method does not modify either string — it returns a brand new string with all values combined.
This method is useful when you need to join multiple strings together in a clear, explicit way. While JavaScript provides other concatenation methods like the + operator and template literals, concat() makes the intent to join strings unmistakable in your code.
Syntax
concat(...strings)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
strings | ...string | — | One or more strings to concatenate. Non-string values are converted to strings automatically. |
Examples
Basic usage
const str1 = "Hello";
const str2 = " ";
const str3 = "World!";
console.log(str1.concat(str2, str3));
// "Hello World!"
This example passes three arguments — a space and two words — producing a single combined string. The order of arguments determines the concatenation order: str1 comes first, then each argument is appended left to right.
Multiple strings
const greeting = "Hello".concat(" ", "from", " ", "JavaScript!");
console.log(greeting);
// "Hello from JavaScript!"
You can pass any number of strings to concat() — it is a variadic method that accepts as many arguments as you need. The method never modifies the string it is called on; it always returns a fresh string.
With non-string values
// concat() converts numbers to strings
console.log("Number: ".concat(42));
// "Number: 42"
// Arrays are converted using their toString() method
console.log("Array: ".concat([1, 2, 3]));
// "Array: 1,2,3"
Numbers and arrays lose their type information during coercion — 42 becomes the string "42" and [1, 2, 3] becomes "1,2,3". For numbers this is harmless, but for objects and arrays the resulting string is rarely what you want to display. When you need structured output, serialize the value with JSON.stringify() before concatenating.
Common Patterns
While concat() works, the + operator and template literals are generally preferred in modern JavaScript for their readability and performance:
// Using concat
const result = str1.concat(str2);
// Using + operator (commonly used)
const result = str1 + str2;
// Using template literals (most flexible)
const result = `${str1}${str2}`;
Use concat() when you need to explicitly signal the intent to join strings, particularly in functional programming contexts where method chaining is preferred. For simple cases, the + operator or template literals are typically more readable.
The three approaches differ in how they handle expressions, readability, and tooling support. Template literals are the newest option and the most flexible, supporting inline expressions and multiline content without escape sequences. The side-by-side comparison below shows the trade-offs.
concat() vs + operator vs template literals
All three approaches produce the same result, but they differ in readability and what modern style guides recommend:
const name = "Alice";
const age = 30;
// concat() — explicit, works in older code
"Hello, ".concat(name, ". You are ", age, " years old.");
// + operator — common, readable for short strings
"Hello, " + name + ". You are " + age + " years old.";
// Template literal — recommended for modern JavaScript
`Hello, ${name}. You are ${age} years old.`;
Template literals are the default choice in contemporary JavaScript: they handle expressions directly, work naturally with multiline strings, and read left-to-right without breaking out of the string to concatenate. The + operator is fine for joining two values. concat() offers no practical advantage over either for string construction — its main niche is being a named method you can pass as a callback.
concat() coerces non-string arguments
When you pass a non-string to concat(), it calls .toString() on it before joining. This is the same behavior as the + operator when one side is a string:
"Value: ".concat(42); // "Value: 42"
"Items: ".concat([1, 2, 3]); // "Items: 1,2,3"
"Flag: ".concat(true); // "Flag: true"
"Nothing: ".concat(null); // "Nothing: null"
"Missing: ".concat(undefined); // "Missing: undefined"
Objects call their toString() method, which usually returns "[object Object]" unless overridden. If you need to serialize objects into strings, use JSON.stringify() rather than relying on implicit coercion.
Strings are immutable
concat() never modifies the original string. All string methods in JavaScript return new string values — the original cannot be changed. This means calling str.concat("x") without assigning the result has no effect.