Template Strings
A template string is a “regular” JavaScript string seeded with placeholders. At runtime, your code replaces the placeholders with real values.
Denote a placeholder with . Place the variable or function inside the curly braces and it will be evaluated at runtime.
Here’s an example:
Here’s another example that uses a template string as a parameter to .
In the above example, the placeholder is a function.
This is a nice shortcut, especially when you contrast it against the plain JS equivalent:
I have trained myself to use the backtick character whenever I need to define strings. You never know when you might want to introduce some data into a string at run-time.
You’ll see a video showcasing template strings in the next chapter.
Template strings actually support a bit more functionality called “Tagged Templates.” These allow you to pre-process the string before it’s emitted. I’ve never seen that functionality used in the real world so I’m not covering it here. Read about there here and decide for yourself whether you think you’ll use them: https://basarat.gitbooks.io/typescript/docs/template-strings.html