Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Working with Strings Template Literals

Devin Cushard
Devin Cushard
2,236 Points

Now, 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);

2 Answers

There 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
Devin Cushard
2,236 Points

Very helpful, thank you!