Open In App

JavaScript String Operators

Last Updated : 27 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

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 “GeeksforGeeks”.

Javascript




let str1 = "Geeks";
let str2 = "forGeeks";
let result = (str1 + str2);
console.log(result);


Output

GeeksforGeeks

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 “GeeksforGeeks”,

Javascript




let str1 = "Geeks";
let str2 = "forGeeks";
  
// Concatenation assignment
str1 += str2; 
console.log(str1);


Output

GeeksforGeeks

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads