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

Better way of putting variables inside a string?

Concatenating strings and variables with the + sign can be a bit ugly, so I did a bit of research and found this page: http://stackoverflow.com/questions/3304014/javascript-variable-inside-string-without-concatenation-like-php

Ignore the first answer on that page (it's obsolete) – it turns out you can use backticks ` and dollar signs $ and curly braces {} to put your variables directly inside a string, like so:

var adjective = prompt('what did you call me?');
document.write(`I know u r ${adjective} but what am I?`);

It worked for me in my workspace (on Chrome), give it a shot! Anyone aware of any limitations to this way of doing things, other than that it's not supported by older browsers?

1 Answer