What is the point of concatenation?

I don’t understand why you wouldn’t just type:

console.log(‘Hello World’);

instead of

console.log('Hello ’ + ‘World’);

Is there a greater point to this? Can someone give me a good example? Thank you!

In that particular example I don’t really see any added value so I see why you ask.

String concatenation does allow you to mix strings with variables, expressions and functions that return strings (or things that can be displayed as strings).

console.log( 'Hello, ' + personName);

console.log("There are only " + calcDaysToChristmas() + " days 'til Christmas!"

console.log("Lucky numbers are: " + myArray);

console.log( genderAppropriateGreeting(customer.gender) + " " + customer.name );

Ahhh… okay, these are great examples. Thank you, this makes a lot more sense!

1 Like