LESSON 7

Strings

Learning objective: Work with text using strings and template literals.

Understand

Strings hold text data.

Strings are written in quotes. You can join them with +, but template literals using backticks and ${} are cleaner for inserting variables. Strings have handy properties like .length and methods like .toUpperCase().

Analogy: A template literal is like a fill-in-the-blank sentence where variables slot in.

See It in Action

Template literals:

let name = "Sam";
console.log(`Hello, ${name}!`);
How it works: The backticks let you embed ${name} directly in the text, producing 'Hello, Sam!'.

Try It Yourself

  1. Store your name in a variable.
  2. Build a greeting with a template literal.
  3. Log the string's .length.

Quick Quiz

What do backtick template literals let you do easily?

Challenge

Build a personalized message using a template literal.

Success condition: Your message correctly inserts a variable into text.