I recently found out about JavaScript's Template Literals, and they help a lot with readability. But would it be worth changing my code from now on to these Template Literals, or should I keep using Strings?

Example of Template Literal vs. String


var name = {
    first: John,
    last: Smith

'Hello' + name.first + name.last + '.';

Template Literal

var name = {
    first: John,
    last: Smith

`Hello ${name.first + name.last}.`;

As you can see above, they help a lot with readability (as I stated above), but when reading the MDN page, it seems to not be fully supported by all browsers. Android default, IE, and IE mobile don't support it. While IE is notoriously bad, it is still widely used. I don't want to make a script using Template Literals and have most of the users use IE.

Would using the Template Literals over Strings be worth the change?


This is the case for most new features and need time to be adapted and integrated.

If you plan to work with multiple browsers then until it is matured I would say no as it would just be increased maintenance, however if you are in a position where you can choose what browsers your clients need to run on then by all means make the best of it and hopefully the more adaption it sees the faster it will be integrated into the others.

So in short until it's supported on all the browsers you feel comfortable with then no unless you don't mind the extra overhead

| improve this answer | |
  • 1
    You could, of course, write your code in ECMAScript 2015, or even the in-development ECMAScript 2016, and compile it to something the client understands, such as ECMAScript 5. – Jörg W Mittag Apr 12 '16 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.