...

Strings and Number Concatenation

In this lesson, you'll learn about concatenation between a string and a number.

When you use the + operator with a string and a number, JavaScript converts the number to a string and concatenates them. For example:

let message = "The total is: ";
let number = 42;
let result = message + number; // Concatenates the string and the number
console.log(result); // Outputs: "The total is: 42"

In the example above, the number 42 is converted to a string and appended to the string "The total is: ".

Try running the code sample below to see how string and number concatenation works!

Loading...

Output (Console)