Skip to content

Chapter 9 of 33

Strings and Template Literals

Process immutable Unicode text with methods, interpolation, and tagged templates.

34 minutes 10 quick checksBy Subha Prasad
Lesson 9 of 33Course navigation

Lesson content

Read, practise, then check your understanding

Strings are immutable UTF-16 sequences. Methods such as slice, includes, startsWith, replace, split, trim, and case conversion return new values.

Templates

const user = "Mira";
const completed = 7;
const message = `${user} completed ${completed} chapters.`;

Template literals support expressions, multiline text, and tagged processing. Length and indexing count UTF-16 code units, so some characters occupy two positions; for...of iterates code points more appropriately. Locale-sensitive comparison and formatting use Intl. Never insert untrusted strings through HTML parsing merely because a template makes it convenient—use DOM text APIs or correct contextual escaping.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes string?
Which JavaScript term matches this description: An immutable sequence of UTF-16 code units.
Which statement best describes template literal?
Which JavaScript term matches this description: Backtick text supporting interpolation and multiline content.
Which statement best describes code point?
Which JavaScript term matches this description: A Unicode value that may occupy one or two UTF-16 code units.
Which statement best describes slice?
Which JavaScript term matches this description: A method returning a selected substring without modifying the original.
Which statement best describes tagged template?
Which JavaScript term matches this description: A function call receiving template literal segments and substitutions.

0 of 10 checks passed

Your progress is saved on this device.