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.
What students will learn in this module
Every question in Module 8
Quick questions
- Do template literals use backticks instead of quotes?ANoBYes
- Does ${} let you embed a variable inside a template literal?AYesBNo
- Can single quotes interpolate a variable with ${}?ANoBYes
- Is
Hi ${name}valid template literal syntax?AYesBNo - 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 doesWraps a string in backticks instead of quotesMatch it to what it doesEmbeds 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 doesFill in the blanks
let msg = _Hello, ${name}!`;Hint: Type the symbol that opens a template literal.
let msg = `Hello, ${name}!_;Hint: Type the symbol that closes a template literal.
let msg = `Hello, __name}!`;
Hint: Type the symbol that starts an embedded expression inside a template literal.
let msg = `Hello, ${name_!`;Hint: Type the symbol that closes an embedded expression.
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);
