[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/String/concat [Back]  [Original]

String.prototype.concat() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String.prototype.concat()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.

concat()

In this article

const str1 = "Hello";
const str2 = "World";

console.log(str1.concat(" ", str2));
// Expected output: "Hello World"

console.log(str2.concat(", ", str1));
// Expected output: "World, Hello"

js
concat(str1)
concat(str1, str2)
concat(str1, str2, ... , strN)

strN

str

concat()

+ += concat()

concat()

js
let hello = "Hello, ";
console.log(hello.concat("Kevin", ". Have a nice day."));
// Hello, Kevin. Have a nice day.

let greetList = ["Hello", " ", "Venkat", "!"];
"".concat(...greetList); // "Hello Venkat!"

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

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.concat


Web Proxy Viewer  |  New URL  |  Original Page