Sunday, September 19, 2021

JavaScript Tagged Template Literals (strings)

 Template literals (Template strings) - JavaScript | MDN

Template literals are literals delimited with backticks (`), allowing embedded expressions called substitutions.

  • Untagged template literals result in strings, which makes them useful for string interpolation (and multiline strings, since unescaped newlines are allowed).
  • Tagged template literals call a function (the tag function) with an array of any text segments from the literal followed by arguments with the values of any substitutions, which is useful for DSLs.
Tag functions don't even need to return a string!




No comments: