In JavaScript, you can use the +
operator to concatenate two or more strings. Here’s an example:
let firstName = "John";
let lastName = "Doe";
let fullName = firstName + " " + lastName;
console.log(fullName); // Output: John Doe
You can also use the concat
method to achieve the same result:
let firstName = "John";
let lastName = "Doe";
let fullName = firstName.concat(" ", lastName);
console.log(fullName); // Output: John Doe
In addition, you can use template literals (introduced in ECMAScript 6) to concatenate strings in a more readable way:
let firstName = "John";
let lastName = "Doe";
let fullName = `${firstName} ${lastName}`;
console.log(fullName); // Output: John Doe
+ There are no comments
Add yours