To concatenate two strings in JavaScript, you can use the `+` operator or the `concat()` method of the String object.
In this example,
str1
and str2
with values "Hello"
and "World"
respectively.str1
and str2
using the +
operator and store the result in a variable named result
.result
to the console.let str1 = "Hello";
let str2 = "World";
let result = str1 + str2;
console.log(result);
HelloWorld
In this example,
str1
and str2
with values "apple"
and "banana"
respectively.concat()
method to concatenate str1
and str2
and store the result in a variable named result
.result
to the console.let str1 = "apple";
let str2 = "banana";
let result = str1.concat(str2);
console.log(result);
applebanana
In this tutorial, we learned How to Concatenate Two Strings in JavaScript language with well detailed examples.