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 trial

JavaScript

Can you just use template literals all the time to keep code consistent for strings?

As I am completing the Javascript Basics course, I really like the way that template literals look and work compared to single and double quotation marks for strings. I think it looks neater in terms of concatenation and you can just stay consistent in your code instead of having to use escape characters or worrying about what type of quotation marks you use. In an effort to stay consistent, is it acceptable in the industry to just use template literals for all strings even if you are not inserting a variable into the string? Is there any drawbacks to doing it that way?

Thanks for reading.

Juan Luna Ramirez
Juan Luna Ramirez
9,038 Points

I can't think of any drawbacks to doing it.

I personally use quotes because I can clearly see when a string will always be the same value. This has been useful for debugging and reading code in general. Using back-ticks lets my mind know that some evaluating will probably need to take place. But this is just my preference. You should try to do different things to see what works for you or the dev team.

2 Answers

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

I don't see why not, I think the main reason they aren't taking over as the main string literal replacement is because it's es6 and es6 isn't completely utilized in every browser/browser version. But yeah, you'd avoid concatenation and escaping quotes so yeah, have at it and use those template literals.

Thank you both Juan and Dane for the help! I really appreciate it.