Welcome to my website

The Template Literal

Template literals are a useful and fun way to add expressions within a string. In otherwords, instead of working with painfully tedious string concatenation you simply use a template literal and add whatever expression you need to without all the +'s and " "'s. The syntax is symple, instead the single or double quote to start and end the string, the ` is used and adding an expression is done by putting it inside of curly braces with a dollar sign before it ex: ${expression goes here}.

Code Example

let firstName = "Patrick";
let lastName = "Dwyer";
let deservesFinalGradeOf = 101
console.log(`Hello, my name is ${firstName}, my last name is ${lastName}, and I really think my grade for this should be ${deservesFinalGradeOf}.  Thank you for coming to my TED talk`);
                

Another code example

let a = 100;
let b = 200;
let booleanTrue = true;
let booleanFalse = false;
alert(`With a template literal I can use my operators within a string a + b = ${a + b}, true or false equates to ${booleanTrue || booleanFalse}, true and false is ${booleanTrue && booleanFalse}, or whatever else your heart desires. `);