JavaScript es6 template literals

Template literals are a new syntax to create strings in JavaScript

Embedding expressions in a string is now possible using template literals thus there's a new way to embed expressions into strings effectively interpolating the values done using syntax ${expression}
within a string for instance

const text = 'Hello world'
const string = `Say ${text}` // Say hello world.

You're not only limited to that you can as well perform more advanced expressions and arithmetics as well

const string = `${1 + 2}` // returns 3

strings that spawn more than one line are now possible with template literals initially the only way to create strings that spawn multiple lines was to break it up in parts the syntax below is now possible

const text = `
loading....
processing...`

Comments

Popular posts from this blog

Open-graph meta data tags introdution

What is 'this.' keyword in JavaScript

How to create zip archives in nodejs

what is 'array.includes' function in JavaScript

How to build a twitter retweet bot using JavaScript