I discovered the interesting possibilities of template literals with ES6 and I was wondering: apart from browsers compatibility, is there any possible 'limitation' of using ONLY template literally for any scenario when dealing with strings?
We successfully use it in every location except import
statements with Babel. It will throw an error there.
It makes it nice for extending code to drop in variables, much like always wrapping single parameter fat arrow functions with (
)
does.
We thought the same thing you did, and began using it everywhere instead of '
and it works. We also checked the MDN and there is nothing saying you can't use it, but it has some quirks such as indenting console.log
s by preserving characters, but the short answer is JavaScript and 99% of libraries don't care about spaces or linebreaks, so its not necessary until you get into a wild use case.
Edit
We have since converted to use eslint-config-airbnb
which by default, enforces usage of single quotations for everything, except JSX (which is double quote). It also enforces grave accents only when using template literals.
I consider this config fairly defacto-standard and its ruleset is extremely well-informed and backed by reason. I would recommend setting your proverbial clocks to it.
If you have any questions, definitely create an issue in the Airbnb GitHub. Target any questions to ljharb
.