Recall & Review
beginner
What are template literals in JavaScript?
Template literals are string literals allowing embedded expressions. They use backticks (`) instead of quotes and can include placeholders with ${expression}.
Click to reveal answer
beginner
How do you embed a variable inside a template literal?
Use the syntax ${variableName} inside backticks. For example: `Hello, ${name}!` will insert the value of name.
Click to reveal answer
beginner
What advantage do template literals have over regular strings?
They allow multi-line strings without special characters and easy insertion of variables or expressions directly inside the string.
Click to reveal answer
beginner
Show an example of a multi-line string using template literals.
Example:
const message = `Hello
World!`;
console.log(message);
This prints:
Hello
World!Click to reveal answer
intermediate
Can you include expressions inside template literals? Give an example.
Yes. You can include any JavaScript expression inside ${}. Example:
const sum = `${2 + 3}`; prints '5'.Click to reveal answer
Which symbol is used to start and end a template literal?
✗ Incorrect
Template literals use backticks (`) to start and end the string.
How do you insert a variable named 'user' inside a template literal?
✗ Incorrect
Variables are inserted inside ${} inside template literals.
What will this code output?
`const a = 5; console.log(`Value is ${a * 2}`);`
✗ Incorrect
Expressions inside ${} are evaluated, so 5 * 2 = 10.
Which of these is a benefit of template literals?
✗ Incorrect
Template literals allow multi-line strings without needing escape characters.
What will this print?
`console.log(`Hello\nWorld`);`
✗ Incorrect
Template literals preserve new lines, so \n creates a new line.
Explain how to use template literals to create a greeting message including a person's name and age.
Think about how to write a sentence like 'Hello, Alice! You are 30 years old.' using variables.
You got /3 concepts.
Describe the advantages of template literals compared to traditional string concatenation.
Consider how template literals make code easier to read and write.
You got /4 concepts.