ECMAScript 2015 (also known as ES2015 or ES6) gave us template literals. They’re a really convenient way to create multi-line strings and/or strings that contain data. But they have no IE support and they can’t be polyfilled. The old-school way is to use string concatenation.
You can use string concatenation to create multi-line strings:
Notice that I’m using the
+ operator to concatenate the strings.
The parentheses are optional, but I think they make it nice and readable.
Expressions, variables, and function calls
You can also concatenate expressions, variables, and function calls.
The parentheses are necessary here. Otherwise, the result would be
"Fifteen is the same as 510". This is due to type coercion.
Hopefully these examples are enough to get your feet wet with string concatenation. It’s just a fancy term for “joining strings together”.
For more information, check out Concatenating strings in the MDN Web Docs.
If you have questions, feedback, or any other suggestions, please do email me. I'd love to hear from you!