O'Reilly logo

Rediscovering JavaScript by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required