Shanu Khera
Notes by Shanu Khera

Follow

Notes by Shanu Khera

Follow
Javascript notes - Part 6 - Template literals

Javascript notes - Part 6 - Template literals

String interpolation and multiline strings in Javascript

Shanu Khera's photo
Shanu Khera
·Feb 20, 2021·

1 min read

Play this article

Template literal is one of the best features in modern Javascript if not the best. Once You start using them, you will forget the old way of concatenating strings together just for including values from variables, etc.

Before

var welcome_message = "Hello <b>" + name + "</b>, Welcome to our website.<br/>" + 
"Use this email - <b>" + email + "</b> and password - <b>" + password + "</b> to login."

After

var welcome_message = `
    Hello <b>${name}</b>, Welcome to our website.<br/> 
    Use this email - <b>${email}</b> and password - <b>${password}</b> to login.
`
 
Share this