Skip to main content

Command Palette

Search for a command to run...

Template Literals in JavaScript

Updated
1 min readView as Markdown
Template Literals in JavaScript

Template Literals is the Javascript Syntax to handle the statement like when we have string with some of var or value included. so we can fix it through this syntax (``).

let name = "Jags";
const message = `my name is ${name}` // my name is Jags
console.log(message)

We can use numbers too

let age = 35;
const message = `my age is ${age}` 
console.log(message) // my age is 35

Its shows line break as implementation

let place = "noida"
const message = `I live in ${place}
its is in the UP India.`
console.log(message)
//I live in noida
//its is in the UP India.

Also can perform calculations

const message = `do you know 85 * 76 = ${85 * 76}`
console.log(message) //do you know 85 * 76 = 6460

Summary

Template Literals helps the developer to reduce the syntex in coding to show the value is the string.