JavaScript String Operators
JavaScript String Operators are used to manipulate and perform operations on strings. There are two operators which are used to modify strings in JavaScript. These operators help us to join one string to another string.
Type of JavaScript String Operators
There are two type of String Operators in JavaScript, these are:
- String Concatenate Operator
- String Concatenate Assignment Operator
We will explore all the above methods along with their basic implementation with the help of examples.
String Concatenate Operator
Concatenate Operator in JavaScript combines strings using the ‘+’ operator and creates a new string that includes the contents of the original strings in which Concatenate string1 and string2, ensuring the first character of string2 immediately follows the last character of string1.
Syntax:
str1 + str2
Example: In this example, we are Concatenating str1 and str2 using the ‘+’ operator, the result variable holds the string “w3wiki”.
Javascript
let str1 = "Beginner" ; let str2 = "forBeginner" ; let result = (str1 + str2); console.log(result); |
w3wiki
String Concatenate Assignment Operator
In this, we perform a concatenation assignment by using the ‘+=’ operator to add the value of a variable or string to an existing string variable.
Syntax:
str1 += str2
Example: In this example, The str1 variable is concatenated with str2 using +=. After the operation, str1 becomes “w3wiki”,
Javascript
let str1 = "Beginner" ; let str2 = "forBeginner" ; // Concatenation assignment str1 += str2; console.log(str1); |
w3wiki
Contact Us