JavaScript Code

How to include variables in a string using JavaScript?

Problem Statement

given a variable and a string, include the variable in a string via interpolation


to include a variable or an expression in a string in JavaScript, we can use template strings. template strings interpolate the variables or expressions in a string

`hello ${name}. welcome to javascript tutorials.`


1. given a string in variable name, include the variable in the template string greeting

let name = 'Arjun'; //normal string
let greeting = `hello ${name}. welcome to javascript tutorials.`;