Template Literals

Also known as String Literals or Template Strings
This uses the Backtick ` to enclose the string characters


var myString1 = "one" 
var myString2 = "two"
var myString3 = `text $(myString1) more text $(myString2)`

Multi-Line

This preserves the line breaks

var myString3 = `text $(myString1) 
   more text
   $(myString2)`

var myString1 = 100; 
var myString4 = `some text $("$" + myString1)`;

With Expressions

var myString1 = 'one plus one is ${ 1 + 1 }'; 

let bool1 = true;
let myString2 = 'the opposite of true is ${!bool1}';


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext