Create a new string by adding sting characters in javascript
You can create a new string by adding string characters in JavaScript using the following methods:
Method 1: Using the +
operator
You can use the +
operator to concatenate two or more strings. Here's an example:
let str1 = "Hello";
let str2 = "World";
let result = str1 + " " + str2;
console.log(result); // Output: "Hello World"
Method 2: Using the concat()
method
You can use the concat()
method to concatenate two or more strings. Here's an example:
let str1 = "Hello";
let str2 = "World";
let result = str1.concat(" ", str2);
console.log(result); // Output: "Hello World"
Method 3: Using template literals
You can use template literals to create a new string by adding string characters. Here's an example:
let str1 = "Hello";
let str2 = "World";
let result = `${str1} ${str2}`;
console.log(result); // Output: "Hello World"
Method 4: Using the join()
method
You can use the join()
method to concatenate an array of strings into a single string. Here's an example:
let arr = ["Hello", "World"];
let result = arr.join(" ");
console.log(result); // Output: "Hello World"
These are some of the ways you can create a new string by adding string characters in JavaScript.