Technical skill practice
JavaScript String Interpolation: Build a Status Message with Template Literals
Template literals use backticks and insert expression values at ${...}. Ordinary single- or double-quoted strings do not perform that interpolation. Keep the value you insert separate from the punctuation that marks the expression.
The task
Prepare a queue-status message with a calculated remaining count, then deliberately show a literal placeholder for documentation.
Runnable Node 22 example
const assert = require('node:assert/strict');
const completed = 3;
const total = 8;
const message = `Packed ${completed} of ${total}; ${total - completed} remain.`;
assert.equal(message, 'Packed 3 of 8; 5 remain.');
assert.equal('Packed ${completed}', 'Packed ${completed}');
const placeholder = `Use \${completed} in the template.`;
assert.equal(placeholder, 'Use ${completed} in the template.');
console.log(message);
console.log(placeholder);
Expected output and explanation
The first template evaluates the subtraction before inserting its result, so the final message contains five remaining items. The ordinary quoted string leaves its placeholder text untouched. Escaping the dollar-sign sequence inside the template also keeps that sequence literal.
This makes template literals useful for readable text construction, but interpolation is not a validation step. If the inputs are wrong types, the expression can produce an unexpected result before it becomes text. This fixture supplies known numeric counts.
Output from the example
Packed 3 of 8; 5 remain.
Use ${completed} in the template.
Pitfall to check
Interpolating text does not make it safe HTML, SQL or a shell command. Use the output context’s proper API and handling. This script creates console text only and makes no browser-rendering claim.
Questions, answered
Can I put function calls inside ${...}?
Yes, expressions can be evaluated there. Keep side effects deliberate so formatting a message does not unexpectedly perform unrelated work.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.