Getting Literal With ES6 Template Strings | JavaScript Template String
EngManager,WebDeveloperRelationsStringsinJavaScripthavebeenhistoricallylimited,lackingthecapabilitiesonemightexpectcomingfromlanguageslikePythonorRuby.ES6TemplateStrings[1](availableinChrome41+),fundamentallychangethat.Theyintroduceawaytodefinestringswithdomain-specificlanguages(DSLs),bringingbetter:StringinterpolationEmbeddedexpressionsMultilinestringswithouthacksStringformattingStringtaggingforsafeHTMLescaping,localizationandmore.RatherthanstuffingyetanotherfeatureintoStringsasweknowthemto...
Eng Manager, Web Developer Relations
Strings in JavaScript have been historically limited, lacking the capabilities one might expect coming from languages like Python or Ruby. ES6 Template Strings[1] (available in Chrome 41+), fundamentally change that. They introduce a way to define strings with domain-specific languages (DSLs), bringing better:
String interpolation Embedded expressions Multiline strings without hacks String formatting String tagging for safe HTML escaping, localization and more.Rather than stuffing yet another feature into Strings as we know them today, Template Strings introduce a completely different way of solving these problems.
SyntaxTemplate Strings use back-ticks (``) rather than the single or double quotes were used to with regular strings. A template string could thus be written as follows:
var greeting = `Yo World!`;So far, Template Strings havent given us anything more th...