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

How to get user's ip address in JavaScript

How to make a static http server in nodejs using express

Array concat method in JavaScript

What is 'this.' keyword in JavaScript

How to create promises in JavaScript