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!
Using template literals and tagged templates • JavaScript for impatient programmers (ES2021 edition)
No comments:
Post a Comment