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!"