Template Literals

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Template Literals

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

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

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1`Hi ${name}!` AWrong - missing curly braces around name
2`Total: ${price + tax}` BWrong - single quotes don't support ${} interpolation
3Wraps a string in backticks instead of quotes C`Hello!`
4Embeds a variable's value directly inside a string DA template literal that calculates and inserts an expression
5'Hi ${name}' E${score}
6`Hi $name` FA template literal that inserts the value of name

Definitions

${}

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let msg = _Hello, ${name}!`;
2.
let msg = `Hello, ${name}!_;
3.
let msg = `Hello, __name}!`;
4.
let msg = `Hello, ${name_!`;
5.
let greeting = `Total: __price + tax}`;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let a = 'Hi ${name}';
B let b = `Hi ${name}`;
C console.log(b);
Question 2
A let x = `Sum: ${a+b}`;
B let y = `Sum: (a+b)`;
C console.log(x);
Question 3
A let m = `A${1}B`;
B console.log(m);
C let n = `A{1}B`;
D console.log(n);
Question 4
A let p = "Hi ${name}";
B let q = `Hi ${name}`;
C console.log(q);
Question 5
A let s = `Age: ${age}`;
B let t = `Age: [age]`;
C console.log(s);

Answer Key

Template Literals
Section A: Quick Questions
Q1
B — Yes
Q2
A — Yes
Q3
A — No
Q4
A — Yes
Q5
B — No
Section B: Match the Pairs
Q1
`Hi ${name}!` → A template literal that inserts the value of name
Q2
`Total: ${price + tax}` → A template literal that calculates and inserts an expression
Q3
Wraps a string in backticks instead of quotes → `Hello!`
Q4
Embeds a variable's value directly inside a string → ${score}
Q5
'Hi ${name}' → Wrong - single quotes don't support ${} interpolation
Q6
`Hi $name` → Wrong - missing curly braces around name
Section C: Definitions
Q1
${} — Syntax used inside backticks to embed a variable or expression directly into a string.
Section D: Fill in the Blanks
Q1
let msg = `Hello, ${name}!`;
Q2
let msg = `Hello, ${name}!`;
Q3
let msg = `Hello, ${name}!`;
Q4
let msg = `Hello, ${name}!`;
Q5
let greeting = `Total: ${price + tax}`;
Section E: Spot the Error
Q1
A — Single quotes don't support ${} interpolation - use backticks.
Q2
B — Use ${} not () for interpolation inside template literals.
Q3
C — Missing the dollar sign - it should be ${1}, not {1}.
Q4
A — Double quotes don't support ${} interpolation - use backticks.
Q5
B — Interpolation needs curly braces {}, not square brackets [].