String Concatenation

Joining strings together.

Examples

Using + Operator

Joining strings with the plus operator.

let text1 = "Hello";
let text2 = "World";
let text3 = text1 + " " + text2;
console.log(text3);

Using concat()

Using the concat() method.

let text1 = "Hello";
let text2 = "World";
let text3 = text1.concat(" ", text2);
console.log(text3);

Adding Number and String

If you add a number and a string, result is a string.

let x = "10";
let y = 20;
let z = x + y;
console.log(z); // "1020"

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.