String Interpolation

In ES6 version of JavaScript this feature was introduced where we can insert or interpolate variables into string using template literals.

Example:

const myPet = 'armadillo';
console.log(`I own a pet ${myPet}.`);

// Output: I own a pet armadillo.

Example:

const myName = 'Johnson';

  

const myCity = 'London';

  

console.log(`My name is ${myName}. My favorite city is ${myCity}.`)

// Output: My name is Johnson. My favorite city is London.

Last updated