Course contentsShow
← JavaScript
Lesson 178 of 2,7235. StringsFree lesson

Concatenating with concat and the + Operator

Combine multiple strings using the concat method or the more common + operator for string building.

Concatenating with concat and the + Operator

You'll learn how to join multiple strings together using two different methods: the concat() method and the + operator.


What is Concatenation?

Concatenation means joining strings end-to-end to create a new, longer string. Think of it like connecting train cars together — each string is a car, and you're linking them into one continuous train.

The + Operator (Most Common)

The simplest and most popular way to concatenate strings is with the + operator:

let greeting = "Hello" + " " + "world";
console.log(greeting); // "Hello world"

let firstName = "Jane";
let lastName = "Doe";
let fullName = firstName + " " + lastName;
console.log(fullName); // "Jane Doe"

You can chain as many strings together as you need, and you can mix string literals with variables.

The concat() Method

The concat() method is an alternative approach. You call it on a string and pass other strings as arguments:

let part1 = "Hello";
let part2 = " ";
let part3 = "world";
let message = part1.concat(part2, part3);
console.log(message); // "Hello world"

// Multiple arguments at once
let result = "I".concat(" love", " JavaScript");
console.log(result); // "I love JavaScript"

Which Should You Use?

The + operator is more common and readable, so most developers prefer it for everyday string building. The concat() method works well when you have many strings to join at once, but in modern JavaScript, template literals are often even better for complex cases.

Key Takeaway: Use the + operator to join strings together (most common), or use the concat() method to concatenate multiple strings in a single method call.