Skip to content

Instantly share code, notes, and snippets.

@getify
Last active November 4, 2016 14:39
Show Gist options
  • Save getify/105df0a0c17892243a37c4fced1d3a8b to your computer and use it in GitHub Desktop.
Save getify/105df0a0c17892243a37c4fced1d3a8b to your computer and use it in GitHub Desktop.
// All of the following are ways that template literals are *NOT* `strictly better` than " or ' delimited strings
// RE: https://ponyfoo.com/articles/template-literals-strictly-better-strings
// valid syntax, but doesn't turn on strict mode
`use strict`;
// invalid syntax
const x = { `hello world`: 42 };
// invalid syntax
const { `hello world`: a } = x;
// invalid syntax
import foo from `foo.js`;
@getify
Copy link
Author

getify commented Sep 15, 2016

@bevacqua

I said string literals not template literals. The point is that if (like me) many people use regular strings in those places (which is valid) and they just start changing all strings to templates as you suggest, they're going to accidentally discover these cases the hard way.

If I didn't know these cases already, and I followed your blog's advice and then tripped over these cases, I'd be frustrated that the advice was less-than-complete, lacking nuance/context, and/or border-line link-baity & disingenuous.

Just to be clear, my feedback isn't for you to rewrite your article or even change its conclusion. It's to add caveat/clarification to your "strictly better" claim that there are multiple cases in valid reasonable JS (not just JSON) where backticks aren't legal.

Take that feedback as you will. I'll drop the subject.

@evandavis
Copy link

I have to agree with @getify. I ran --fix on my React repo and was surprised by how many strings were not converted: module imports would be invalid, and JSX props require a {} wrapper around template literals.

For now, it's easier (for me) to just use backticks when I need the features of a template literal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment