Is there a downside to using ES6 template literals syntax without a templated expression?

北城以北 提交于 2019-11-26 23:03:20

The most significant reason not to use them is that ES6 is not supported in all environments.

Of course that might not affect you at all, but still: YAGNI. Don't use template literals unless you need interpolation, multiline literals, or unescaped quotes and apostrophes. Much of the arguments from When to use double or single quotes in JavaScript? carry over as well. As always, keep your code base consistent and use only one string literal style where you don't need a special one.

Always use string literals. In this case YAGNI is not correct. You absolutely will need it. As some point, you will have add a variable to your string, at which point you will either need to change single quotes to backtickets, or use the dreaded '+'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!