Code Editor
Learn
Variables

String Interpolation II

In the newest version of JavaScript (ES6) we can insert variables into strings with ease, by doing two things:

  1. Instead of using quotes around the string, use backticks (this key is usually located on the top of your keyboard, left of the 1 key).
  2. Wrap your variable with ${myVariable}, followed by a sentence. No +s necessary.

ES6 string interpolation is easier than the method you used last exercise. With ES6 interpolation we can insert variables directly into our text.

It looks like this:

let myPet = 'armadillo' console.log(`I own a pet ${myPet}.`) // Output: 'I own a pet armadillo.'

In the example above, the backticks (`) wrap the entire string. The variable (myPet) is inserted using ${}. The resulting string is:

I own a pet armadillo.
Report a Bug
If you see a bug or any other issue with this page, please report it here.