Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Callback Functions in JavaScript Introduction to Callback Functions Creating a Simple Callback Function

${teacher.name} ?

Hi, why did Andrew use ${teacher.name} and not just teacher.name?

Thanks

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! This is really just what we call "syntactic sugar" which makes the code more readable. It's called a JavaScript template literal and is covered in this workshop. The console.log function shown in the video is as follows:

console.log(`${teacher.name} - ${teacher.role}`);

Because there's a hyphen in the middle, if we wanted to do this without the templating the same console.log would need to look like this:

console.log(teacher.name + " - " + teacher.role);

Many consider the latter form to be less readable and intuitive.

You can find further documentation on JavaScript template literals here

Hope this helps! :sparkles:

Chris Shaw
Chris Shaw
26,676 Points

Hi Alina Antemir,

In JavaScript as of ES2015 (aka ECMAScript 6), this is known as string interpolation which you will find in other languages with varying syntaxes. The difference with this compared to simply declaring a variable in say console.log is that we can inject an object directly into a string without needing to concatenate it or use multiple arguments.

You can read more about template literals (as they're officially called) at the below link.

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals

Happy coding!

Hi Chris Shaw , Jennifer Nordell ,

Thank you coming back to me so quick. It makes sense now.

Thank you so much, Alina