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 trialJAE IN KIM
Front End Web Development Techdegree Student 6,794 Pointsinside {}, we can write anything without making Variable?
const name=prompt("what's your name?")
const message=hello, ${name}, It's ${2*4}.
console.log(message);
like this, can I use ${} anytime without assigning Var as long as string is inside tick marks??
1 Answer
Zimri Leijen
11,835 Pointswhen you make a template literal like that, the ${}
acts as a placeholder.
anything in between the curlies will be parsed as javascript, so yes, you can do something like:
console.log(`The sum of 8 and 4 is ${8+4}`);
or
const a = 8;
const b = 4;
console.log(`${a} + ${b} = ${a+b}`);
or even
const a = 8;
const b = 4;
const sum = (a, b) => a+b;
console.log(`${a} + ${b} = ${sum(a,b)}`);