Concept Flow - String concatenation in output
Start
Define strings
Concatenate strings
Output result
End
The program starts by defining strings, then joins them together, and finally shows the combined result.
let greeting = "Hello"; let name = "Alice"; let message = greeting + ", " + name + "!"; console.log(message);
| Step | Action | Expression | Result | Output |
|---|---|---|---|---|
| 1 | Define greeting | greeting = "Hello" | Hello | |
| 2 | Define name | name = "Alice" | Alice | |
| 3 | Concatenate greeting + ", " | "Hello" + ", " | Hello, | |
| 4 | Concatenate previous + name | "Hello, " + "Alice" | Hello, Alice | |
| 5 | Concatenate previous + "!" | "Hello, Alice" + "!" | Hello, Alice! | |
| 6 | Assign to message | message = "Hello, Alice!" | Hello, Alice! | |
| 7 | Output message | console.log(message) | Hello, Alice! |
| Variable | Start | After Step 1 | After Step 2 | After Step 6 | Final |
|---|---|---|---|---|---|
| greeting | undefined | Hello | Hello | Hello | Hello |
| name | undefined | undefined | Alice | Alice | Alice |
| message | undefined | undefined | undefined | Hello, Alice! | Hello, Alice! |
String concatenation joins strings using + operator. Add spaces or punctuation as separate strings. Store result in a variable. Use console.log() to output. Example: "Hello" + ", " + "Alice" + "!" => "Hello, Alice!"
+ 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