You can concatenate a first name and last name into a single string using different methods in JavaScript.
Method 1: Using the `+` Operator
let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; console.log(fullName); // Output: "John Doe"
Simple and direct method using `+` for string concatenation.
Method 2: Using Template Literals (ES6)
let firstName = "John"; let lastName = "Doe"; let fullName = `${firstName} ${lastName}`; console.log(fullName); // Output: "John Doe"
Best practice: More readable and efficient than `+` operator.
Method 3: Using `concat()` Method
let firstName = "John"; let lastName = "Doe"; let fullName = firstName.concat(" ", lastName); console.log(fullName); // Output: "John Doe"
Uses `.concat()` method to merge multiple strings.
Method 4: Using `join()` (Best for Arrays)
let nameArray = ["John", "Doe"]; let fullName = nameArray.join(" "); console.log(fullName); // Output: "John Doe"