0

Now we have the template literal in ES6 for example:

const str = `this is a string`;

or

const str1 = 'string';
const str2 = `this is a ${str1}`;

So I feel like it is more consistent to always use backticks and do away with quotes altogether. So in the above example I could instead define str1 this way:

const str1 = `string`;

I realise that this is to some extent opinion based - but is there any technical reason not to do this, e.g. is there a performance penalty for using the template literal syntax rather than the string literal (quotes) syntax?

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Sam Redway
  • 7,605
  • 2
  • 27
  • 41
  • 3
    Penalty yes or no, IMO the different literals can and should be used to signal different intent to the reader/programmer. A `''` string will not have any interpolations, so I may care about it differently than if I saw a template literal. – deceze Mar 29 '17 at 09:09
  • http://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation – Stephan-v Mar 29 '17 at 09:09
  • 2
    There are also tooling problems, as is exemplified by the obsolete code colorization of SO. – Denys Séguret Mar 29 '17 at 09:10
  • 1
    @Stephan-v it doesn't seem to answer the question which is about the cases when there's no interpolation. – Denys Séguret Mar 29 '17 at 09:10
  • 1
    Even with no interpolation, one would imagine string literals have to be faster as the engine doesn't need to check to see if any work needs to be done - but this could be a difference of microseconds. I agree with deceze, if I see a template literal I instinctively look for interpolation - this could be a difference of full seconds. – CodingIntrigue Mar 29 '17 at 09:14

0 Answers0