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 Object-Oriented JavaScript Getters and Setters Setters

Sarah Breidenbach
Sarah Breidenbach
4,490 Points

With console.log('setter called: ${owner}'); what are the $ and curly bracket for?

${owner}

2 Answers

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

Hi there! The dollar sign and the curly brackets are part of a "new-ish" type thing in JavaScript called a JavaScript Template Literal. They are really nice to use, and I highly recommend learning about them. Treehouse has a 9-minute workshop on them and I can almost guarantee it's worth your time. Take a look at it here.

But for a small example, consider this code:

var x = 10;
var y = 20;

If I then wanted to do a console.log() to print out the results of the multiplication of those two numbers, I could do either:

console.log("The product of " + x + " and " + y + " is " + x * y);

Or I could do this:

console.log(`The product of ${x} and ${y} is ${x * y}`);

In both cases, the following string will be logged to the console: The product of 10 and 20 is 200. But take a look at how much the JavaScript Template literal simplifies all the concatenation and makes your code look cleaner.

Hope this helps! :sparkles:

Those are template strings. It's taking the value of an expression and retuning it. Check out the docs on template literals.

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