String-Tagged Templates

This lesson will teach you how to use a tagged template as a reusable way to format code.

The last detail you are going to learn about TypeScript and strings is what you may call a tagged template. This concept is rarely used but offers a different way of specifying a function before opening a backquote. Each group of strings and placeholders is defined by a dollar sign $ and curly braces {}.

In this case, you still provide an expression, but you can have the whole string manipulated by the method (placeholders and strings before and after placeholders).

In the following snippet, the third line uses string interpolation but, at the start, it has analyzeString which is the string template.

The code below does not compile because we have not yet defined the template. ❌

Get hands-on with 1200+ tech skills courses.