In previous exercises, we assigned strings to variables. Here, you will learn how to insert the content saved to a variable into a string.
The + operator, known until now as the addition operator, is used to interpolate (insert) a string variable into a string, as follows:
let myPet = 'armadillo'; console.log('I own a pet ' + myPet + '.'); // Output: 'I own a pet armadillo.'
In the example above, we saved the value ‘armadillo‘ to the myPet variable. On the second line, the + operator is used to combine three strings: I own a pet, the value saved to myPet, and . (period). We log the result of this interpolation to the console as:
I own a pet armadillo.