The most common way to concatenate strings with variables is by using the
+ operator. This operator can be used to join strings together.
In the above example, we have two variables
lastName. By using the
+ operator, we can merge the values of these variables along with a space between them to create the
fullName variable. Finally, we output the
fullName variable to the console.
It's important to note that when concatenating with the
+ operator, we need to make sure to include any necessary spacing or punctuation marks within the string.
Declare a new variable
age and assign it a value of 25.
Create a new variable
message and concatenate the
firstName variable with the string
", aged " and the
Assign the result to the
console.log() function to print out the
Sign up to start coding
Already have an account?