Tutorials Modern JavaScript (ES6+) for Beginners

Template Literals & Modern Strings

Learn Template Literals & Modern Strings in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
Template Literals & Modern Strings
Lesson 4 of 12 · Part 2 — Write Less Code · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 4/12 · Read time: ~12 min · Level: Beginner · ES version: ES2015 (ES6) and above

Template Literals & Modern Strings

Template literals use backticks (`) instead of quotes. They make strings with variables, HTML snippets, and multi-line text readable — essential for UI work in React and email templates in Node.

Basic interpolation

const name = 'Sandeep';
const course = 'ES6 Basics';

// Old
const msg1 = 'Hi ' + name + ', welcome to ' + course;

// ES6 — template literal
const msg2 = `Hi ${name}, welcome to ${course}`;

Multi-line strings

const emailHtml = `
  <h1>Your certificate is ready</h1>
  <p>Hi ${student.name},</p>
  <p>You completed ${courseTitle}.</p>
`;
🌍 Real-world example — Dynamic quiz result message
function resultMessage({ name, score, total }) {
  const pct = Math.round((score / total) * 100);
  const badge = pct >= 80 ? '🏆' : '📚';
  return `${badge} ${name}: you scored ${score}/${total} (${pct}%).`;
}

resultMessage({ name: 'Priya', score: 18, total: 20 });
// "🏆 Priya: you scored 18/20 (90%)."

Useful string methods (ES6+)

'hello world'.includes('world');   // true
'  trim me  '.trim();              // 'trim me'
'file.pdf'.endsWith('.pdf');       // true
'user@email.com'.startsWith('user'); // true
💡 Tip: Use template literals for any string with 2+ variables — your code reviews will thank you.
⚠️ Common Mistake: Forgetting backticks and using single quotes with ${name} — that prints literal "${name}", not the variable.
👨‍🏫 Teaching note: Exercise: build an invoice string with 4 interpolated fields (customer, item, qty, total).

Continue learning

Previous: Arrow Functions Explained

Next: Destructuring — Arrays & Objects

Course home: All 12 lessons

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain JavaScript in the context of Modern JavaScript (ES6+) for Beginners.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. How to structure your answer (60–90 seconds) Define JavaScript i…
Mid Detailed
What are common mistakes teams make with Components when using Modern JavaScript (ES6+) for Beginners?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Components in plain language…
Senior Detailed
How would you debug a production issue related to State in a Modern JavaScript (ES6+) for Beginners application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define State in plain language for…
Junior Detailed
Describe a real-world scenario where Performance mattered in a Modern JavaScript (ES6+) for Beginners project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Performance in plain languag…
Mid Detailed
Compare two approaches to API integration—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define API integration in plain lan…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Modern JavaScript (ES6+) for Beginners
Course syllabus
Part 1 — Modern Basics
Part 2 — Write Less Code
Part 3 — Data & Collections
Part 4 — Async & Modules
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details