{"id":134,"date":"2026-05-05T10:08:16","date_gmt":"2026-05-05T10:08:16","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=134"},"modified":"2026-05-05T10:08:20","modified_gmt":"2026-05-05T10:08:20","slug":"template-literals","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals","title":{"rendered":"Template Literals"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Template Literals are a modern feature in JavaScript that make working with strings easier and more flexible. They allow developers to create dynamic strings, include variables, and write multi line text without complicated syntax.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What are Template Literals<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Template Literals are strings defined using backticks instead of single or double quotes. They allow embedded expressions using a special syntax called interpolation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Template literals use backticks <code><\/code> and the ${} placeholder to insert variables or expressions inside a string.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let name = \"Ali\";<br>let message = `Hello, ${name}! Welcome to JavaScript.`;<br>console.log(message);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the variable name is directly inserted into the string without using concatenation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Key Features<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">String Interpolation<br>You can insert variables or expressions directly into a string using ${} which makes the code cleaner and easier to read.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Multi Line Strings<br>Template literals allow you to write strings across multiple lines without using special characters like newline symbols.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let text = `This is line one<br>This is line two<br>This is line three`;<br>console.log(text);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expression Evaluation<br>You can perform calculations or include JavaScript expressions inside template literals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let a = 5;<br>let b = 10;<br>console.log(`The sum is ${a + b}`);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use Cases<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating dynamic messages for users<br>Building HTML templates in web applications<br>Simplifying string concatenation<br>Generating formatted output<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Advantages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Improves code readability<br>Reduces the need for complex string concatenation<br>Supports multi line text easily<br>Makes dynamic content creation simple<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Template Literals are an essential feature in modern JavaScript. They simplify string handling and make code more readable and efficient, especially when working with dynamic data.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Advanced JavaScript > ES6+ Features > Template Literals<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777975656486\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777975656294\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-134","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Template Literals - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=template-literals\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Template Literals - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=template-literals\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-05T10:08:20+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=template-literals\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=template-literals\",\"name\":\"Template Literals - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-05T10:08:16+00:00\",\"dateModified\":\"2026-05-05T10:08:20+00:00\",\"description\":\"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=template-literals#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=template-literals\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=template-literals#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced JavaScript > ES6+ Features > Template Literals\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Template Literals - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals","og_locale":"en_US","og_type":"article","og_title":"Template Literals - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-05T10:08:20+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals","url":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals","name":"Template Literals - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-05T10:08:16+00:00","dateModified":"2026-05-05T10:08:20+00:00","description":"Learn JavaScript template literals to create dynamic strings with interpolation, multi line text, and cleaner code easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=template-literals"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=template-literals#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Advanced JavaScript > ES6+ Features > Template Literals"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}