{"id":29846,"date":"2019-04-30T21:18:53","date_gmt":"2019-04-30T13:18:53","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=29846"},"modified":"2019-04-26T15:58:17","modified_gmt":"2019-04-26T07:58:17","slug":"ecmascript-6-template-literals","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/","title":{"rendered":"How to Use ES6 Template Literals in JavaScript"},"content":{"rendered":"<p>In programming, the term <strong>\u201cliteral\u201d<\/strong> refers to the <strong>notation of values<\/strong> in code. For instance, we notate a string value with a <strong>string literal<\/strong> that are characters enclosed in double or single quotes (<code>\"foo\"<\/code>, <code>'bar'<\/code>, <code>\"This is a string!\"<\/code>).<\/p>\n<p><strong><a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Template_literals\" target=\"_blank\">Template literals<\/a><\/strong> were introduced in <strong>ECMAScript 6<\/strong>. They work quite similarly to string literals; they produce <strong>template values<\/strong> and <strong>raw template values<\/strong>, both of which are strings.<\/p>\n<p>However, unlike string literals, template literals can produce values that are <strong>multi-lined strings<\/strong>, something you can achieve in a string literal only by <strong>adding new line characters<\/strong> (<code>\\n<\/code>) to it.<\/p>\n<p>Template literals can also <strong>create strings with other values<\/strong> (derived from expressions) for which you would have to use the <strong>plus operator<\/strong> in a string literal (<code>\"your id is:\" + idNo<\/code>; where <code>idNo<\/code> is a variable expression with a numeric value).<\/p>\n<p>All these features make template literals more preferable to <strong>create string values<\/strong>.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/ecmascript-6\/\">ECMAScript 6 \u2013 10 Awesome New Features<\/a>\n\t\t\t\t<\/p>\n<h2>Syntax of template literals<\/h2>\n<p>The delimiter of a template literal is the <strong>backtick <code>`<\/code> character<\/strong> (also know as backquote character or grave accent symbol). An expression inside the literal (the value of which is <strong>evaluated during runtime<\/strong> and included in the final value produced by the literal) is enclosed in <strong>curly braces <code>{}<\/code><\/strong> with a <strong>preceding dollar sign <code>$<\/code><\/strong>.<\/p>\n<pre>\r\n`string ${someExpression} more string`\r\n<\/pre>\n<p>Here are some <strong>examples of template literals<\/strong> producing <strong>unchanged<\/strong>, <strong>substituted<\/strong> (expressions replaced with their evaluated values), and <strong>multi-lined<\/strong> strings.<\/p>\n<pre>\r\nconsole.log(`hello`);\r\n\/\/ hello\r\n\r\nvar name = \"Joan\";\r\nconsole.log(`hello ${name}`);\r\n\/\/ hello Joan\r\n\r\nconsole.log(`Dear Joan,\r\nWelcome.`);\r\n\/\/ Dear Joan,\r\n\/\/ Welcome.\r\n<\/pre>\n<h2>Escaping & raw template values<\/h2>\n<p>In a template literal, the <code>`<\/code> (backtick), <code>\\<\/code> (backslash), and <code>$<\/code> (dollar sign) characters <strong>should be escaped<\/strong> using the <strong>escape character <code>\\<\/code><\/strong> if they are to be included in their template value.<\/p>\n<p>By default, all escape sequences in a template literal are <strong>ignored<\/strong>. If you want to include it in the output, you need to use its <strong>raw template value<\/strong>.<\/p>\n<pre>\r\nconsole.log(`inline code in markup: \\`code\\``);\r\n\/\/ inline code in markup: `code`\r\n\r\nvar name = \"Joan\";\r\n\r\nconsole.log(`hello \\${name}.`);\r\n\/\/ hello ${name}.\r\n\r\nconsole.log(String.raw`hello \\${name}.`);\r\n\/\/ hello \\${name}.\r\n<\/pre>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/raw\" target=\"_blank\"><code>String.raw<\/code><\/a> method <strong>outputs raw template values<\/strong> (the raw string form of a template literal). In the above code, the function call of the <code>raw<\/code> method is referred to as <strong>\u201ctagged template\u201d<\/strong>.<\/p>\n<h2>Tagged templates<\/h2>\n<p>A tagged template is a <strong>function call<\/strong> where, <strong>in place of the usual parentheses<\/strong> (with optional parameters) besides the function name, <strong>there\u2019s a template literal<\/strong> from which the function gets its arguments.<\/p>\n<p>So, instead of calling a function like this:<\/p>\n<pre>\r\nfoo(ArgumentsForFoo);\r\n<\/pre>\n<p>It is called like this:<\/p>\n<pre>\r\nfoo`ATemplateStringProvidingArgumentsForFoo`;\r\n<\/pre>\n<p>The function <code>foo<\/code> is called a <strong>tag function<\/strong>. Its first argument received from the template literal is an <strong>array<\/strong> called the <strong>template object<\/strong>.<\/p>\n<p>The template object (an array) holds <strong>all the string values<\/strong> interpreted from the template literal and has a <code>raw<\/code> property (another array) that holds <strong>all the raw (un-escaped) string values<\/strong> interpreted from the same literal.<\/p>\n<p>Following the template object, the arguments of the tag function include <strong>all the <em>evaluated<\/em> external values<\/strong> present in that literal (the ones enclosed in the curly braces <code>${}<\/code>).<\/p>\n<p>In the code below, the <code>foo<\/code> function is created to <strong>output its arguments<\/strong>. The function is then called <strong>in the tagged template fashion<\/strong>, with a template literal carrying two expressions (<code>name<\/code> and <code>id<\/code>).<\/p>\n<pre>\r\nvar name = \"John\";\r\nvar id = 478;\r\n\r\nfoo`hello ${name}. your id is: ${id}.`;\r\n\r\nfunction foo(){\r\n  console.log(arguments[0]);\r\n  \/\/ Array [ \"hello \", \". your id is: \", \".\" ]\r\n\r\n  console.log(arguments[1]);\r\n  \/\/ John\r\n\r\n  console.log(arguments[2]);\r\n  \/\/ 478\r\n}\r\n<\/pre>\n<p>The first argument outputted is the <strong>template object<\/strong> carrying all the strings interpreted from the template literal, the second and third arguments are the <strong>evaluated values<\/strong> of the expressions, <code>name<\/code> and <code>id<\/code>.<\/p>\n<h3>The <code>raw<\/code> property<\/h3>\n<p>As mentioned before, the template object has a <strong>property called <code><a href=\"https:\/\/developer.mozilla.org\/he\/docs\/Web\/JavaScript\/Reference\/template_strings#Raw_strings\" target=\"_blank\">raw<\/a><\/code><\/strong> which is an array containing <strong>all the raw (un-escaped) string values<\/strong> interpreted from the template literal. This is how you can access the <code>raw<\/code> property:<\/p>\n<pre>\r\nvar name1 = \"John\",\r\nname2 = \"Joan\";\r\n\r\nfoo`hello \\${name1}, ${name2}, how are you both?`;\r\n\r\nfunction foo(){\r\n  console.log(arguments[0]);\r\n  \/\/ Array [\"hello ${name1}, \",\", how are you both?\"]\r\n\r\n  console.log(arguments[0].raw);\r\n  \/\/ Array [\"hello \\${name1}, \",\", how are you both?\"]\r\n\r\n  console.log(arguments[1]);\r\n  \/\/ Joan\r\n}\r\n<\/pre>\n<h3>Use cases of tagged templates<\/h3>\n<p>Tagged templates are useful when you need to <strong>break a string<\/strong> into separate parts like it\u2019s often the case in a URL, or while parsing a language. You\u2019ll find a collection of <strong>tagged template examples <a href=\"https:\/\/exploringjs.com\/es6\/ch_template-literals.html#_examples-of-using-tagged-template-literals\" target=\"_blank\">here<\/a><\/strong>.<\/p>\n<p>Other than IE, template literals are <strong>supported in all major browsers<\/strong>.<\/p>\n<p>Below, you can find some examples of tag functions with <strong>different <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Signature\/Function\" target=\"_blank\">signatures<\/a><\/strong> that represent the arguments:<\/p>\n<pre>\r\nvar name = \"John\";\r\n\r\nfoo`hello ${name}, how are you both?`;\r\nbar`hello ${name}, how are you both?`;\r\n\r\n\r\nfunction foo(...args){\r\n  console.log(args);\r\n  \/\/ Array [ Array [\"hello \",\", how are you both?\"], \"John\"]\r\n}\r\n\r\nfunction bar(strVals, ...exprVals){\r\n  console.log(strVals);\r\n  \/\/ Array [ \"hello \", \", how are you both?\" ]\r\n\r\n  console.log(exprVals);\r\n  \/\/ Array [ \"John\" ]\r\n}\r\n<\/pre>\n<p>In the <code>bar<\/code> function, the first parameter (<code>strVals<\/code>) is the <strong>template object<\/strong> and the second one (that uses the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/Spread_operator\" target=\"_blank\">spread syntax<\/a>) is an array that gathered <strong>all the evaluated expression values<\/strong> from the template literal passed to the function.<\/p>\n<h3>Put the string together<\/h3>\n<p>If you want to <strong>obtain the whole sentence<\/strong> (derived from the literal) inside the tag function, <strong>concatenate all values<\/strong> of the arrays carrying the template strings and the evaluated expression values. Like this:<\/p>\n<pre>\r\nfunction foo(strs, ...exprs) {\r\n\r\n  \/\/ if there are any expressions included in the literal\r\n  if (exprs.length !== 0) {\r\n      var n = strs.length - 1,\r\n      \t\tresult = '';\r\n      for (var i = 0; i &lt; n; i++) {\r\n          result += strs[i] + exprs[i];\r\n      }\r\n      result += strs[n];\r\n      console.log(result);\r\n      \/\"Hello John.\"\r\n  }\r\n\r\n  \/\/ if there are no expressions included in the literal\r\n  else\r\n  console.log(strs[0]);\r\n}\r\n\r\nname = 'John';\r\n\r\nfoo`Hello ${name}.`;\r\n<\/pre>\n<p>The <code>strs<\/code> array holds <strong>all the strings<\/strong> found in the literal and <code>exprs<\/code> holds <strong>all the evaluated expression values<\/strong> from the literal.<\/p>\n<p>If even one expression value exists concatenate each array value of <code>strs<\/code> (except the last one) with the same-index value of <code>exprs<\/code>. Then, at the end, add the last value of the <code>strs<\/code> array to the concatenated string, <strong>forming a complete sentence<\/strong> this way.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/useful-javascript-statements\/\">4 Useful JavaScript Statements You Should Know<\/a>\n\t\t\t\t<\/p>","protected":false},"excerpt":{"rendered":"<p>In programming, the term \u201cliteral\u201d refers to the notation of values in code. For instance, we notate a string value with a string literal that are characters enclosed in double or single quotes (&#8220;foo&#8221;, &#8216;bar&#8217;, &#8220;This is a string!&#8221;). Template literals were introduced in ECMAScript 6. They work quite similarly to string literals; they produce&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[3687,4117,511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use ES6 Template Literals in JavaScript - Hongkiat<\/title>\n<meta name=\"description\" content=\"In programming, the term &quot;literal&quot; refers to the notation of values in code. For instance, we notate a string value with a string literal that are\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use ES6 Template Literals in JavaScript\" \/>\n<meta property=\"og:description\" content=\"In programming, the term &quot;literal&quot; refers to the notation of values in code. For instance, we notate a string value with a string literal that are\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-30T13:18:53+00:00\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"How to Use ES6 Template Literals in JavaScript\",\"datePublished\":\"2019-04-30T13:18:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/\"},\"wordCount\":744,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"ECMAScript\",\"Javascripts\",\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/\",\"name\":\"How to Use ES6 Template Literals in JavaScript - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2019-04-30T13:18:53+00:00\",\"description\":\"In programming, the term \\\"literal\\\" refers to the notation of values in code. For instance, we notate a string value with a string literal that are\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/ecmascript-6-template-literals\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use ES6 Template Literals in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use ES6 Template Literals in JavaScript - Hongkiat","description":"In programming, the term \"literal\" refers to the notation of values in code. For instance, we notate a string value with a string literal that are","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:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/","og_locale":"en_US","og_type":"article","og_title":"How to Use ES6 Template Literals in JavaScript","og_description":"In programming, the term \"literal\" refers to the notation of values in code. For instance, we notate a string value with a string literal that are","og_url":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2019-04-30T13:18:53+00:00","author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"How to Use ES6 Template Literals in JavaScript","datePublished":"2019-04-30T13:18:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/"},"wordCount":744,"commentCount":3,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["ECMAScript","Javascripts","Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/","url":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/","name":"How to Use ES6 Template Literals in JavaScript - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2019-04-30T13:18:53+00:00","description":"In programming, the term \"literal\" refers to the notation of values in code. For instance, we notate a string value with a string literal that are","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/ecmascript-6-template-literals\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Use ES6 Template Literals in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7Lo","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=29846"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29846\/revisions"}],"predecessor-version":[{"id":41984,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29846\/revisions\/41984"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=29846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=29846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=29846"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=29846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}