How to use ‘+’ operator In Javascript
The + operator can be used to concat or add an extra character to the string by using it in between the string and the character to be added.
NOTE: It allows you to add characters either at the start or at the end of a string.
Syntax:
"initialString" + "extraCharacter";
Example: The below code implements the + operator to add a character to a string in JavaScript.
const str1 = "GeeksforGeek" + "s";
const str2 = "J" + "avaScript";
console.log(str1, str2);
Output
w3wiki JavaScript
Add Characters to a String in JavaScript
In JavaScript, A string is a combination of multiple characters joined together to form a meaningful word. It can be a name or anything else. You can add an extra character to a string after it is defined to complete it or to practice adding characters.
There are several ways available in JavaScript to achieve this task as listed below:
Table of Content
- Using ‘+’ operator
- Using the concat() method
- Using template literals
- Using slice() method
- Using substring() method
- Using substr() method
- Using Array.prototype.join() Method