Difference between String Interpolation and String concatenation

Hello Code Academy Community,

I am trying to understand the difference between String interpolation and String concatenation.

Let’s take the following example:

If I want as an output to have the following sentence: "I own a pet armadillo. "

I can do either with a simple String concatenation :

const myPet = 'armadillo'; 
console.log('I own a pet' + ' ' + myPet);
// Output:  I own a pet armadillo.

Or with a String Interpolation:

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

What is the difference? When should I use the String Interpolation or the String Concatenation?

Link of the course: https://www.codecademy.com/courses/introduction-to-javascript/lessons/variables/exercises/string-interpolation-ii


String interpolation/template literals where introduced in a JavaScript update (ES6). I find the template literals easier to read and work with, and would preferable use them, however:

Can I use... Support tables for HTML5, CSS3, etc

IE does not support template literals. So then either: inform users your website does not support IE or you would need to transpile to ES5 (earlier version) using something like babel.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.