3
kiki
4y

I don’t know about you but I use backticks for every string in js. I want to know that I can always use quotes and apostrophes and backticks ensure this. Also they allow templates and Babel got me covered when it comes to old browsers.

I don’t see the reason why should I use something but backticks in 2020

Again,
` — kiki
“, ‘ — boubas

Comments
  • 0
    @highlight

    const foo = `"quotes" and "single quotes" can't do this without escaping`
  • 1
  • 1
    @iiii oof mate. That's not salt what I can smell from here though, that's a seasoning
  • 4
    I wouldn't, personally. Backticks to me signify that I'm expecting to see embedded vars and/or multiline strings. If I see backticks and there's neither of those, that rings a little bell in my head that says something doesn't seem right and needs investigating further. I think you'll find most standard JS linting rulesets will say similar, and flag any such "misused" template literals.

    Plus, they're not going to be sensible in *every* situation. If you had a pre-formatted string, using no variables, that contained backticks, that'd be kinda insane.
  • 1
    @AlmondSauce I thought the same way but once I tried it I felt so relieved that I don't need escaping neither double nor single quotes
  • 0
    I agree. Single or double quote consistently.
  • 1
    @AlmondSauce Yeah, ESLint will warn you (or possibly chuck errors) about that when there are no embedded variables or if there are no (double) quotes inside.
  • 2
    @AlmondSauce This.
    Use only what you need, and no more.
  • 0
  • 4
    I prefer semantic correctness.
  • 0
    would you write a "babel and webpack for dumbasses" if you have the tine?
  • 0
    @SortOfTested so you escape characters?
  • 1
    @uyouthe
    If I'm not interpolating, I don't use an interpolation instruction.
  • 1
    @SortOfTested so you pick single quotes when your text contains double quotes and you pick double quotes when your text contains an apostrophe. If it contains both you either concatenate strings or escape characters, because there is no other way since you don’t use backticks when there is no templates involved
  • 2
    @uyouthe
    I don't tend to have large constant blocks of text in my code, so that's not really an issue for me. To my mind that sort of data is/should be configuration.
  • 2
    @SortOfTested my everyday workflow includes rapid prototyping with i18n which accepts strings
  • 2
    @uyouthe
    Sounds like it's unqjue to your use case.

    Our i18n powers from id and loads dictionary files. The transformations load from a factory which serves xliff notation rules, so the only thing that manifests in the front end code/templates is a keyed binding target identifier (ex: viewId:displayFieldId). The strings, pluralization, conditional sets, etc are all in external config.

    Translations load from a rest call with the local language. The code itself has none of the content.
Add Comment