Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

String.prototype.concat

Joins strings together.

Available since: ES3

Syntax

str.concat(str1, str2, /* … */)

Parameters

ParameterTypeDescription
str1, …stringStrings to append.

Return value

stringA new string.

Examples

Joining three strings:

console.log('Hello'.concat(', ', 'Anna'));

Output:

Hello, Anna

The same with the + operator and a template literal:

const name = 'Anna';
 
console.log('Hello, ' + name);
console.log(`Hello, ${name}`);

Output:

Hello, Anna
Hello, Anna

Notes

In practice concat() is rarely used: the + operator and template literals are shorter and clearer.

See also

In the tutorial

  • Strings — Strings in JavaScript — quotes, joining, template literals, length, accessing characters and the first methods.

Thanks for reading!

Donate to the site — we work hard for you.