jskatas.org Continuously Learn JavaScript. Your Way.

Template strings: tagged template strings

Advanced form of template strings.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Tagged template strings, are an advanced form of template strings

  • syntax: prefix a template string with a function to call (without "()" around it)

the tag function can access each part of the template

the 1st parameter receives only the pure strings of the template string

  • the strings are an array
  • expressions are NOT passed to it

the 2nd and following parameters contain the values of the processed substitution

  • the 2nd parameter contains the first expression`s value
  • the 3rd parameter contains the second expression`s value
  • using ES6 rest syntax, all values can be accessed via one variable

Links

Description of tagged template strings.