Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDevin Cushard
2,236 PointsNow, will we always be able to use template literals, or will there be times that we will have to concatenate strings?
const name = prompt('What is your name?');
const message = Hello, ${name}. Welcome to my music site. I'm happy that you came by to visit, ${name}. Please come again and listen to more music.
;
console.log(message);
4 Answers
eotfofiw
Python Development Techdegree Student 824 PointsThere are still environments out there which don't support template strings. The number of those environments is shrinking drastically - but they do still exist.
When you use something like Typescript or Babel to convert your up to date, full features javascript to a target platform (transpiling), you can tell it what version of the ECMAScript (aka JavaScript) standard you want to target.
At that point, you can still use template strings, and the transpiler will handle converting that into string concatenation for you. So that environments that won't understand the backtick can still work.
A great site to check whether a feature of HTML, CSS or JavaScript can be used in your target environment is "can I use": https://caniuse.com/template-literals - this will tell you whether or not you should use string concatenation.
Devin Cushard
2,236 PointsVery helpful, thank you!
Roland Schützenhofer
1,364 PointsAlso, as you might learn later, when working with loops, it might make more sense to use concatenation
Damien Lavizzo
4,265 PointsWow, great question and great answer!