Template Literals, online

Six activities your students do on their own devices. See who's finished, and their scores.

Template Literals in one minute

What students need to know

Backticks mark the start and end of a template literal. This syntax inserts the current value of score into the string.

Template literals are wrapped in backticks (`), not single or double quotes. This correctly wraps text in backticks and embeds name with ${}.

Mistakes students make

  • Single quotes don't support ${} interpolation - use backticks.
  • Use ${} not () for interpolation inside template literals.
  • Missing the dollar sign - it should be ${1}, not {1}.
  • Double quotes don't support ${} interpolation - use backticks.

Discover other journeys with this module

What students will learn in this module

Every question in Module 8

Quick questions

  1. Do template literals use backticks instead of quotes?ANoBYes
  2. Does ${} let you embed a variable inside a template literal?AYesBNo
  3. Can single quotes interpolate a variable with ${}?ANoBYes
  4. Is Hi ${name} valid template literal syntax?AYesBNo
  5. Does Hi $name (without braces) interpolate the variable name?AYesBNo

Key terms

Students type the meaning of:

  • ${}

Match the pairs

`Hi ${name}!`Match it to what it does
`Total: ${price + tax}`Match it to what it does
Wraps a string in backticks instead of quotesMatch it to what it does
Embeds a variable's value directly inside a stringMatch it to what it does
'Hi ${name}'Match it to what it does
`Hi $name`Match it to what it does

Fill in the blanks

  1. let msg = _Hello, ${name}!`;

    Hint: Type the symbol that opens a template literal.

  2. let msg = `Hello, ${name}!_;

    Hint: Type the symbol that closes a template literal.

  3. let msg = `Hello, __name}!`;

    Hint: Type the symbol that starts an embedded expression inside a template literal.

  4. let msg = `Hello, ${name_!`;

    Hint: Type the symbol that closes an embedded expression.

  5. let greeting = `Total: __price + tax}`;

    Hint: Type the symbol that starts an embedded expression inside a template literal.

Spot the error

Question 1

Alet a = 'Hi ${name}';Blet b = `Hi ${name}`;Cconsole.log(b);

Question 2

Alet x = `Sum: ${a+b}`;Blet y = `Sum: (a+b)`;Cconsole.log(x);

Question 3

Alet m = `A${1}B`;Bconsole.log(m);Clet n = `A{1}B`;Dconsole.log(n);

Question 4

Alet p = "Hi ${name}";Blet q = `Hi ${name}`;Cconsole.log(q);

Question 5

Alet s = `Age: ${age}`;Blet t = `Age: [age]`;Cconsole.log(s);