Monday, 5 October 2020

Javascript backtick template literals

 https://medium.com/javascript-in-plain-english/the-real-difference-between-single-quotes-and-double-quotes-in-javascript-3d00bf720bcd


`${var}`


Backtick (` `) literals have 3 big advantages:

  1. Easier string concatenation (“variable interpolation”)
    "string "+variable becomes `string ${variable}`
  2. No need to escape (\) single or double quotes
    "\"Hello World!\"" becomes `"Hello World"`
  3. Multi-line code without new line character (\n)
    "Hello\nWorld!" becomes `Hello
    World`

Backticks also work better for HTML:

No comments:

Post a Comment