Concatenating Strings in JavaScript
Let's explore some operations that you can perform with strings in JavaScript.
Concatenation
Concatenation is the process of combining two strings. This operation is achieved using the +
operator:
1234let wordOne = "Hello"; let wordTwo = "World"; console.log(wordOne + wordTwo);
You can see that concatenation creates a new string by combining two words.
Note
String concatenation does not automatically add spaces. You need to manually include spaces like
string1 + " " + string2
.
Let's create a nicely formatted string through concatenation:
1234let wordOne = "Hello"; let wordTwo = "World"; console.log(wordOne + ", " + wordTwo + "!");
Concatenation with Assignment
The +=
operator allows you to add text to a string-type variable:
12345let text = "Were"; text += "wolf"; text += "!"; console.log(text)
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.33
Concatenating Strings in JavaScript
Swipe to show menu
Let's explore some operations that you can perform with strings in JavaScript.
Concatenation
Concatenation is the process of combining two strings. This operation is achieved using the +
operator:
1234let wordOne = "Hello"; let wordTwo = "World"; console.log(wordOne + wordTwo);
You can see that concatenation creates a new string by combining two words.
Note
String concatenation does not automatically add spaces. You need to manually include spaces like
string1 + " " + string2
.
Let's create a nicely formatted string through concatenation:
1234let wordOne = "Hello"; let wordTwo = "World"; console.log(wordOne + ", " + wordTwo + "!");
Concatenation with Assignment
The +=
operator allows you to add text to a string-type variable:
12345let text = "Were"; text += "wolf"; text += "!"; console.log(text)
Thanks for your feedback!