MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Template Literals (Basics)0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
6.1String Basics6.2Common String Methods6.3Template Literals (Basics)
HomeTutorialsJavaScript for BeginnersTemplate Literals (Basics)
Defining and Calling Functions

Template Literals (Basics)

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Before ES6 (2015), creating dynamic strings or multi-line text in JavaScript required clumsy string concatenation using the plus operator (+) and escape characters (\n). Template Literals (written with backticks `` ... ``) revolutionized string formatting in JavaScript.


1. What are Template Literals?

Template literals are string literals delimited by backticks (` `) instead of quotes (' or "`).

They provide two monumental superpowers:

  1. 1
    String Interpolation: Embedding variables and expressions directly inside strings with ${expression}.
  2. 2
    Native Multi-Line Strings: Preserving newlines and indentation without \n.

2. String Interpolation (${...})

Instead of messy concatenation:

The Old Way (ES5):

1const name = "Sumit";
2const role = "Full-Stack Developer";
3const years = 5;
4 
5const bio = "My name is " + name + ", I am a " + role + " with " + years + " years of experience.";

The Modern Way (Template Literals):

1const name = "Sumit";
2const role = "Full-Stack Developer";
3const years = 5;
4 
5const bio = `My name is ${name}, I am a ${role} with ${years} years of experience.`;

Any Valid JavaScript Expression Inside ${...}:

You can perform mathematical calculations, function calls, or ternary logic inside ${}:

1const price = 499;
2const gst = 0.18;
3 
4console.log(`Total Price: ₹${price * (1 + gst)}`);
5// Total Price: ₹588.82
6 
7const user = { name: "Neha", isPremium: true };
8console.log(`Status: ${user.isPremium ? "VIP Member" : "Standard User"}`);

3. Multi-Line Strings Made Simple

Before template literals, multi-line HTML templates required concatenation on every line:

The Old Way:

1var html = "<div class='card'>\n" +
2 " <h2>Title</h2>\n" +
3 " <p>Description</p>\n" +
4 "</div>";

With Template Literals:

1const cardHtml = `
2 <div class="card">
3 <h2>Course Title</h2>
4 <p>Learn Full-Stack Development at MSK Institute.</p>
5 </div>
6`;

Every newline, space, and indentation is preserved exactly as written!


4. Escaping Backticks Inside Template Literals

If you need to include a literal backtick inside a template literal, escape it with \`:

1const codeSnippet = `Use \`const\` for immutable variable bindings.`;

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What characters are used to enclose a Template Literal in JavaScript?
Question 2
What is the placeholder syntax used to embed variables and expressions inside a template literal?
Question 3
What is the output of const x = 5; const y = 3; console.log(${x} + ${y} = ${x + y});?
Question 4
Can a template literal span across multiple lines without using \n escape characters?
Question 5
Can a ternary operator be embedded inside ${...} in a template literal?
Next Lesson

Defining and Calling Functions

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Common String MethodsDefining and Calling Functions

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext