Reputation: 60251
With the introduction of template literals for JavaScript, it has much advantage over single quote and double quote as per mentioned in https://ponyfoo.com/articles/template-literals-strictly-better-strings.
In term of performance, there's no obvious different between them as stated in https://medium.com/javascript-in-plain-english/are-backticks-slower-than-other-strings-in-javascript-ce4abf9b9fa
So my question is, is there any case where template literals can't be used other than the case of printing "Testing ${something}"
where then back-tick need a slash as in `Testing \${something}`
I have checked various related existing Stackoverflow
From the stackoverflows, can't see anything that shows a single quote or double quote is required that can't be achieved by backtick, other than stating it as easier distinguish the different purpose.
Upvotes: 2
Views: 764
Reputation: 60251
What I found is, the following can't use backtick
const headers2 = {
`Accept`: `application/json`,
`Content-Type`: `application/json`
};
This will error Uncaught SyntaxError: Unexpected template string
import React from `react`;
This will error stating Parsing error: Unexpected token
Not sure if my findings are legit or there are more cases. Feel free to share.
Updated
3. Using of use strict
`use strict`;
The above is not functioning without any warning.
Upvotes: 4