In this article, we will explain to you how to join two strings in JavaScript. here we will give you four simple examples of how to join two strings in JavaScript.
We can easily combine two strings using the plus operator. so you can see the below example,
const first = "Hello"; const second = "World"; const join = first + second; console.log(join); // "HelloWorld"
We can easily join two strings using Es6 Template literals. so you can see the below example.
const first = "Hello";
const second = "World";
const join = `${first} ${second}`;
console.log(join); // "Hello World"
We can easily combine the first string with the second string into the third variable using += operator. so you can see the below example.
let first = "Hello"; let second = "World"; second += first; // combined second with first console.log(second); // "Pack World"
We can easily combine two strings using the javascript string concat() method. which is take one string argument parameter and it returns the concat string. so you can see the below example.
const first = "Hello";
const greet = first.concat(", World");
console.log(greet); // "Hello, World"