Tagged Template

A template literal may be untagged or tagged. Tags are functions that receive the contents of the provided template literal in two parts: the template object and the evaluated expressions. The template literals we saw so far are untagged, but we may optionally place a tag in front of a template literal.

Before you learn how to write your own tagged template functions, let’s make use of a built-in tagged template function called raw(). Suppose we want to create a string with some embedded special characters. In the next example we create a regular string, but by escaping each special character with a backslash.

 console.log(​'some special characters: ​​\\​​ ​​\\​​n ​​\\​​b ​​\'​​'​);

The output from this ...

Get Rediscovering JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.