The variable count inside ${} is replaced by its value 3.
Step 2: Evaluate the console.log output
The string becomes 'You have 3 new messages.' and prints exactly that.
Final Answer:
You have 3 new messages. -> Option C
Quick Check:
Variable inside ${} = replaced by value [OK]
Hint: Variables inside ${} show their value in template strings [OK]
Common Mistakes:
Thinking ${count} prints literally
Confusing quotes and backticks
Expecting variable name instead of value
4. Find the error in this code snippet:
let user = 'Anna'; console.log('Welcome, ${user}!');
medium
A. Missing semicolon after let declaration
B. Single quotes do not allow variable interpolation
C. Variable user is not declared
D. Backticks are missing around the string
Solution
Step 1: Check string quotes for interpolation
Single quotes ('') do not process ${} as variable placeholders.
Step 2: Identify correct string type for template literals
Backticks (`) are needed to enable variable interpolation.
Final Answer:
Single quotes do not allow variable interpolation -> Option B
Quick Check:
Use backticks for ${} interpolation [OK]
Hint: Use backticks, not single quotes, for ${} variables [OK]
Common Mistakes:
Thinking single quotes support ${} interpolation
Ignoring missing backticks
Assuming variable is undeclared
5. You want to print a message showing a user's name and age using template literals. The variables are name = 'Sam' and age = 25. Which code correctly formats the output as: Hello, Sam! You are 25 years old.
hard
A. console.log(`Hello, ${name}! You are age years old.`);
B. console.log('Hello, ' + name + '! You are ' + age + ' years old.');
C. console.log(`Hello, name! You are age years old.`);
D. console.log(`Hello, ${name}! You are ${age} years old.`);
Solution
Step 1: Use template literals with variables
Backticks and ${} allow embedding variables name and age inside the string.
Step 2: Check each option for correct variable usage
console.log(`Hello, ${name}! You are ${age} years old.`); correctly uses ${name} and ${age} to insert values.
Final Answer:
console.log(`Hello, ${name}! You are ${age} years old.`); -> Option D
Quick Check:
Backticks + ${var} for each variable = correct [OK]
Hint: Use ${variable} inside backticks for multiple variables [OK]
Common Mistakes:
Using variable names without ${} inside template literals
Mixing quotes and backticks incorrectly
Concatenating strings instead of using template literals
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.