what is the difference between
console.log("hello $(nom)");
and
console.log("hello " + nom);
what is the difference between
console.log("hello $(nom)");
and
console.log("hello " + nom);
The first isn’t used correctly.
It should be using ${}
which is interpolation used in template literals. But you do not use it like that. The way you are using it it will just log hello $(nom)
.
Note the backticks used.
const name = 'John'
console.log(`Hello ${name}`) // Hello John
HI @bilalbajou !
Here are the two FCC lessons that talk about Template Literals and Concatenating Strings with the Plus operator if you want to review them.
There is only few difference. It seems that there is no difference in term of performance. But the template literal is easier to read because there isn’t all the " + … + ".
Moreover with the concatenation, you have to escape thé " or the ', which are more used than the backtick `
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.