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 make a Snake Game using JavaScript and html5

Adding Gameover and introduction screen on HTML Canvas

JavaScript intro to classes

How to use canvas context rect method for drawing rectangles

How to draw clouds on HTML5 Canvas