Horje
How to Concatenate Two Variables in JavaScript ?

In JavaScript, you can concatenate two variables (combine their values into a single string) using the + operator.

Example 1: Here, the + operator is used to concatenate the values of firstName, a space character, and lastName into the variable fullName.

Javascript

let firstName = "John";
let lastName = "Doe";
 
let fullName = firstName + " " + lastName;
console.log(fullName); // Outputs "John Doe"

Output

John Doe

Example 2: You can also use the += operator to concatenate and assign the result back to the variable.

Javascript

let firstName = "John";
let lastName = "Doe";
 
let fullName = firstName;
fullName += " " + lastName;
console.log(fullName); // Outputs "John Doe"

Output

John Doe




Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is the use of the Math.random Function in JavaScript ? What is the use of the Math.random Function in JavaScript ?
How to Check if a Variable is of Type Number in JavaScript ? How to Check if a Variable is of Type Number in JavaScript ?
How to Create a Single Line Comment in JavaScript ? How to Create a Single Line Comment in JavaScript ?
How to Create a Multi Line Comment in JavaScript ? How to Create a Multi Line Comment in JavaScript ?
How to Exit a Loop Before it Completes all Iterations in JavaScript ? How to Exit a Loop Before it Completes all Iterations in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14