Two ways of interpolation? , vs +

Hi,
what is the dfference between these two ways of interpolation, i.e. when would I use which:

console.log(‘My age is’, 30)

console.log(My age is’ + 30)

I’m pretty sure I’ve seen both the comma-option and the plus-option in the “Variable” lesson.

Thanks

Neither of those are string interpolation, and both are invalid code (watch out with forum formatting)
string interpolation is replacing placeholders in the string with other strings

const bobs_age = 5;
const s = `bob is ${bobs_age} years old`;

One sends two values to console.log, the other sends a single string

1 Like

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