Introduction
String concatenation helps you join words or messages together to show in the output.
String concatenation helps you join words or messages together to show in the output.
let message = 'Hello, ' + name + '!'; console.log(message);
console.log('Hello, ' + 'world!');
let name = 'Alice'; console.log('Hi, ' + name + '!');
let count = 5; console.log('You have ' + count + ' new messages.');
This program joins strings and variables to create a greeting and an info message, then prints both.
let firstName = 'John'; let lastName = 'Doe'; let age = 30; let greeting = 'Hello, ' + firstName + ' ' + lastName + '!'; let info = 'You are ' + age + ' years old.'; console.log(greeting); console.log(info);
Remember to convert numbers to strings automatically by using + with strings.
You can also use template literals (backticks) for easier string joining, but + is simple and clear.
Use + to join strings and variables for output.
Add spaces inside quotes to keep words separate.
String concatenation helps build clear messages for users.
+ operator do when used between two strings in JavaScript?"Hello" and "World" with a space between them in JavaScript?let name = "Anna";
console.log("Hello, " + name + "!");name holds the string "Anna" and is concatenated with other strings.let greeting = "Hi"; let name = "Sam"; console.log(greeting + name);
Hi Sam?Hello, John Doe! You have 5 new messages. using variables firstName, lastName, and messageCount. Which code correctly concatenates these values with spaces and punctuation?Pass the test and this pattern moves unknown