Home JavaScript String Methods concat() JavaScript String concat() Method Definition In JavaScript, String.prototype.concat() joins the current string with one or more values and returns a new string . The original string never changes. Non-string arguments are converted to text first.
str.concat(a, b, ...) → new joined string
original string → unchanged
numbers / booleans → become text
"Hi" + "!" → often clearer than concat Syntax Call concat on the string you already have. You can pass one value or many.
str.concat(str2);
str.concat(str2, str3); Call What it does str.concat(str2)Joins str and str2 into one new string. str.concat(str2, str3)Joins three (or more) pieces left to right in one call.
Built into JavaScript. Call concat(...) on a string — no import needed. For everyday code, the + operator is usually clearer.
Library declarations str.concat(str2)
str.concat(str2, str3, ...strN) Parameters Parameter Description str2, str3, … Optional. One or more values to append. Each value is converted to a string.
Return Value Return Value Description string A new string made of the original text plus every argument, in order.
JavaScript Examples 1. Basic join 2. Convert values 3. vs + operator Example 1 — Basic concat() Join a greeting and a name into one string.
const hello = "Hello";
const name = "Ada";
const message = hello.concat(", ", name, "!");
console.log(message);
console.log(hello); How It Works Start with pieces. hello and name are separate strings.Join in order. concat(", ", name, "!") builds "Hello, Ada!".Original stays put. hello is still "Hello" because strings do not mutate.Example 2 — Numbers and Other Values Non-string arguments become text before they are joined.
const label = "Score: ";
console.log(label.concat(42));
console.log("Done: ".concat(true));
console.log("Items: ".concat(1, "-", 3)); Score: 42
Done: true
Items: 1-3 How It Works Numbers become text. 42 is written as "42" inside the result.Booleans too. true becomes the string "true".Many args work. Each argument is converted, then joined left to right.Example 3 — concat() vs + Both join strings. Prefer + (or template literals) in most beginner code.
const a = "Code";
const b = "ToFun";
console.log(a.concat(b));
console.log(a + b);
console.log(`${a}${b}`); CodeToFun
CodeToFun
CodeToFun How It Works Same result. All three lines print CodeToFun.Choose clarity. + and template literals are easier to read for most joins.When concat helps. Use it when you already have an array of pieces and call "".concat(...parts).Compatibility
Browser & Runtime Support String.prototype.concat() has been available since the earliest JavaScript engines. Safe everywhere.
✓ Baseline · Widely available
String.concat() Supported in all modern browsers and Node.js. No polyfill needed.
100% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support concat() Excellent
Bottom line: Safe for every environment. Prefer + or template literals for everyday string joining.
Frequently Asked Questions What does String.concat() do? It joins the current string with one or more values and returns a new string. The original string is not changed.
Does concat() change the original string? No. Strings are immutable. Assign the return value if you need the joined text.
Can I pass numbers to concat()? Yes. Numbers, booleans, and most other values are converted to strings, then joined.
Should I use concat() or the + operator? For two or three pieces, + or a template literal is usually clearer. concat() is handy when joining many arguments or spreading an array.
What if I call concat() with no arguments? You get a copy of the original string as a new string value.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful
Helpful Share Copy link Suggestion