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 Interpolation

Could you have written the functions as arrow functions.... such as

var like = (thing) => `I like ${thing}`;

var love=(thing)=> `I love ${thing}`;
Franklyn Roth
Franklyn Roth
16,770 Points

You could even combine both of them into 1 arrow function!

let likeLove = (thing1, thing2) => `I like ${thing1}, but love ${thing2}`;
console.log(likeLove(`beer`, `sleeping`));

2 Answers

Yes! You could do it like this:

let like = thing => `I like ${thing}!`

Notice that I changed var to let and removed the optional parentheses around the parameter

excellent thanks

No problem!

Leoben 1987
Leoben 1987
1,574 Points

Is it better practice to use const for functions? (assuming we don't want to overwrite them later)

Franklyn Roth
Franklyn Roth
16,770 Points

You could even combine both of them into 1 arrow function!

let likeLove = (thing1, thing2) => `I like ${thing1}, but love ${thing2}`;
console.log(likeLove(`beer`, `sleeping`));