Skip to Content
JavaScript
book

JavaScript

by T. J. Crowder
July 2020
Intermediate to advanced content levelIntermediate to advanced
608 pages
15h 43m
English
Wrox
Content preview from JavaScript

10Templates, Tag Functions, and New String Features

In this chapter, you'll learn about ES2015's new template literals and template tag functions, plus new string features such as improved Unicode support, iteration, and added methods.

TEMPLATE LITERALS

ES2015's template literals provide a way to create strings (and other things) using a literal syntax combining text and embedded substitutions. You're familiar with other kinds of literals, such as string literals delimited with quotes ( "hi") and regular expression literals delimited with slashes (/\s/). Template literals are delimited with backticks ( `), also called grave accents. This character is in various places on various different language keyboard layouts; on English-language keyboards it tends to be in the top left near Esc, but again, the location varies.

Template literals come in two varieties: untagged and tagged. We'll look at untagged (standalone) template literals first, then tagged literals.

Basic Functionality (Untagged Template Literals)

An untagged template literal creates a string. Here's a simple example:

console.log(`This is a template literal`); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced JavaScript

Advanced JavaScript

Zachary Shute

Publisher Resources

ISBN: 9781119367956Purchase book